0
点赞
收藏
分享

微信扫一扫

Java Lambda 统计共有多少个单词

月半小夜曲_ 2022-02-17 阅读 76
java

Java Lambda 统计共有多少个单词

		String words = "If you miss the train I'm on You will know that I am gone You can hear the whistle blow a hundred miles A hundred miles a hundred miles";
		
		//统计共有多少个单词
		long wordCount = Stream.of(words).map(word -> word.split(" ")).flatMap(Stream::of).count();
		System.out.println(wordCount);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

举报

相关推荐

0 条评论