0
点赞
收藏
分享

微信扫一扫

Java Lambda 找出最长的单词

phpworkerman 2022-02-17 阅读 60
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";
		
		//找出最长的单词
		Optional<String> maxLongWord = Stream.of(words).map(word -> word.split(" ")).flatMap(Stream::of).collect(Collectors.maxBy(Comparator.comparing(String::length)));
		System.out.println(maxLongWord.get());

                    

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

举报

相关推荐

0 条评论