kratos2333
5/15/2017 - 7:07 AM

Split the sentece and grouping the words by its length

Split the sentece and grouping the words by its length

public static void main(String[] args) {
		String[] string = "you never know what you have until you clean your room".split(" ");
		Map<Integer, List<String>> resultMap = Arrays.stream(string).distinct().collect(Collectors.groupingBy(String::length));
		resultMap.forEach((k,v)-> {
			System.out.printf("The words with lenth of %d %n", k);
			v.forEach(System.out::println);
		});
	}