Stream几乎可以解决常见集合的排序。
注意:排序器只能接收引用数据类型,不能接收基本数据类型。
public class Solution {
@Test
public void solutionTestMap(){
Map map = new HashMap<>();
map.put(1, "333");
map.put(2, "222");
map.put(3, "111");
map.entrySet().stream().sorted(((o1, o2) -> o2.getKey().compareTo(o1.getKey()))).forEach(o-> System.out.println(o));
}
@Test
public void solutionTestList(){
List list=new ArrayList<>();
Collections.addAll(list,7,6,4,5,3,8,9,1,0);
list.stream().sorted((o1,o2)->o2-o1).forEach(o-> System.out.println(o));
}
}
@Test
public void solutionTestArr(){
int[] arr={3,5,4,7,9,3,8,0};
Arrays.stream(arr).sorted().forEach(o-> System.out.println(o));
}



