diff --git a/src/main/java/strman/Strman.java b/src/main/java/strman/Strman.java index 2486956..08ddd2b 100644 --- a/src/main/java/strman/Strman.java +++ b/src/main/java/strman/Strman.java @@ -1290,6 +1290,22 @@ public abstract class Strman { } + /** + * Counts the number of occurrences of each character in the string + * + * @param input The input string + * @return A map containing the number of occurrences of each character in the string + */ + public static Map charsCount(String input) { + if (isNullOrEmpty(input)) { + return Collections.emptyMap(); + } + + return input.chars() + .mapToObj(c -> (char) c) + .collect(groupingBy(identity(), counting())); + } + private static void validate(String value, Predicate predicate, final Supplier supplier) { if (predicate.test(value)) { throw new IllegalArgumentException(supplier.get()); @@ -1309,20 +1325,5 @@ public abstract class Strman { } return countSubstr(value.substring(offset), subStr, allowOverlapping, ++count); } - - /** - * Counts the number of occurrences of each character in the string - * - * @param input The input string - * @return A map containing the number of occurrences of each character in the string - */ - public static Map charsCount(String input) { - if (isNullOrEmpty(input)) { - return Collections.emptyMap(); - } - - return input.chars() - .mapToObj(c -> (char) c) - .collect(groupingBy(identity(), counting())); - } } +