Вывод без приведения к char в sorted.forEach((k, v) -> System.out.println(((char) k.intValue()) + " " + v));
32 2
33 1
44 1
65 1
97 1
98 2
100 3
101 1
104 1
108 3
110 1
111 3
114 1
119 1
package com.javarush.task.task18.task1821;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
/*
Встречаемость символов
*/
public class Solution {
public static void main(String[] args) {
if (args.length > 0) {
String file = args[0];
try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
Map<Integer, Long> map = bufferedReader.lines()
.flatMapToInt(CharSequence::chars)
.boxed()
.collect(Collectors.groupingBy(x -> x, Collectors.counting()));
Map<Integer, Long> sorted = new TreeMap<>(map);
sorted.forEach((k, v) -> System.out.println(((char) k.intValue()) + " " + v));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}