To count number of character of a String using Stream API.we are using IntStream method that convert mapToInt and through forEach method traverse the data.
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class CountChar {
public static void main(String[] args) {
String[] value = { "java", "tech", "note", "com" };
Stream str = Stream.of(value);
IntStream ins = str.mapToInt(h -> h.length());
ins.forEach(System.out::println);
}
}
Output :- 4 4 4 3