-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathTask04Main.java
More file actions
31 lines (25 loc) · 1002 Bytes
/
Task04Main.java
File metadata and controls
31 lines (25 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.task04;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.Comparator;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Task04Main {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
reader.lines()
.map(String::toLowerCase)
.flatMap(line -> Stream.of(line.split("[^\\p{L}\\p{N}]+")))
.filter(word -> !word.isEmpty())
.collect(Collectors.groupingBy(word -> word, Collectors.counting()))
.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.limit(10)
.map(Map.Entry::getKey)
.forEach(word -> System.out.print(word + "\n"));
}
}