5 为什么要分成两组???
public static void main(String[] args) {
String str = "5, 5, 1, 4, 2, 3, 6, 5, 4, 1, 3, 2, 6, 5, 1, 3, 4, 8, 2, 5, 1, 8, 2, 3, 4,5, 3, 8, 2, 1, 1, 9, 8, 2, 10, 7, 1, 5";
List<String> list = new ArrayList<>(Arrays.asList(str.split(",")));
System.out.println(list.toString());
Map<String, Long> map = list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
System.out.println(map);
}
//结果
[5, 5, 1, 4, 2, 3, 6, 5, 4, 1, 3, 2, 6, 5, 1, 3, 4, 8, 2, 5, 1, 8, 2, 3, 4, 5, 3, 8, 2, 1, 1, 9, 8, 2, 10, 7, 1, 5]
{ 1=7, 2=6, 3=5, 4=4, 5=5, 5=2, 6=2, 7=1, 8=4, 9=1, 10=1}
不理解 5 为什么要分成两组??? 求解
还是不理解lamda表达式啊,
数据格式要求严格:" 5, 5, 1 "
这个空格很有灵性啊