fix: change location of others to correct places (#5559)

This commit is contained in:
B Karthik
2024-10-04 23:17:50 +05:30
committed by GitHub
parent 393337fa8e
commit 042d458d34
12 changed files with 42 additions and 21 deletions

View 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();
}
}