How to count number of character from Stream Method in Java 8?

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.


public class CountChar {
	public static void main(String[] args) {
		String[] value = { "java", "tech", "note", "com" };
		Stream<String> str = Stream.of(value);
		IntStream ins = str.mapToInt(h -> h.length());

Output :- 4 4 4 3

Leave a Comment

Your email address will not be published. Required fields are marked *