Strings beginner

String chars as stream

Process string characters as a stream pipeline.

✕ Java 8
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (Character.isDigit(c)) {
        process(c);
    }
}
✓ Java 9+
str.chars()
    .filter(Character::isDigit)
    .forEach(c -> process((char) c));
🔗

Chainable

Use filter, map, collect on character streams.

📐

Declarative

Describe what to do, not how to loop.

🌐

Unicode-ready

codePoints() correctly handles emoji and supplementary chars.

Old Approach
Manual Loop
Modern Approach
chars() Stream
Since JDK
9
Difficulty
beginner
String chars as stream
Available

Available since JDK 8+ (improved in 9+)

String.chars() returns an IntStream of character values, enabling functional processing. For Unicode support, codePoints() handles supplementary characters correctly.

Share 𝕏 🦋 in