如何从List使用Java 8 Streams 获取下一个元素?
如果我迭代a List,我想比较当前与列表的下一个元素.
是否可以使用Java 8 Stream?
比方说,我有一个单词列表
List<String> words = Arrays.asList("Hello alan i am here where are you"+
"and what are you doing hello are you there");
Run Code Online (Sandbox Code Playgroud)
如何按降序排列列表中重复多次的前七个单词?然后单个输入词应按字母顺序排列.所以上面的输出应该是前七个字
you (3)
are (2)
hello (2)
alan (1)
am (1)
and (1)
doing (1)
Run Code Online (Sandbox Code Playgroud)
我正在使用流,lamda在Java 8中这样做.
我正在尝试这种方式.首先对列表进行排序第二次获取单词的地图及其单词列表中的单词数量.
List<String> sortedWords = Arrays.asList("Hello alan i am here where are you and what are you doing hello you there".split(" "))
.stream().sorted().collect(toList());
Map<String, Long> collect =
sortedWords.stream().collect(groupingBy(Function.identity(), counting()));
Run Code Online (Sandbox Code Playgroud)