Streams from Char Sequence
Description
chars()
from the CharSequence
interface returns an IntStream
whose elements are int values representing the characters.
We can use chars()
method on a String,
a StringBuilder
, and a StringBuffer
.
Example
The following code creates a stream of characters from a string, filters out all digits and whitespaces, and prints the remaining characters:
// w ww . ja va 2 s .co m
public class Main {
public static void main(String[] args) {
String str = "5 123,123,qwe,1,123, 25";
str.chars()
.filter(n -> !Character.isDigit((char)n) && !Character.isWhitespace((char)n))
.forEach(n -> System.out.print((char)n));
}
}
The code above generates the following result.