mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
fix: change location of others to correct places (#5559)
This commit is contained in:
20
src/main/java/com/thealgorithms/strings/CountChar.java
Normal file
20
src/main/java/com/thealgorithms/strings/CountChar.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
public final class CountChar {
|
||||
private CountChar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of non-whitespace characters in the given string.
|
||||
*
|
||||
* @param str the input string to count the characters in
|
||||
* @return the number of non-whitespace characters in the specified string;
|
||||
* returns 0 if the input string is null
|
||||
*/
|
||||
public static int countCharacters(String str) {
|
||||
if (str == null) {
|
||||
return 0;
|
||||
}
|
||||
return str.replaceAll("\\s", "").length();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user