String (@NotNull String s, @NotNull CharFilter filter) { StringBuilder result = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (filter.accept(ch)) { result.append(ch); } } return result.toString(); }