Map排序的方式有很多种,两种比较常用的方式:按键排序(sort by key), 按值排序(sort by value).1.按键排序jdk内置的java.util包下的TreeMap<K,V>既可满足此类需求,向其构造方法 TreeMap(Comparator<? super K> comparator) 传入我们自定义的比较器即可实现按键排序. public class MapSortDemo { public static void main(String[] args)
Map排序的方式有很多种,这里记录下自己总结的两种比较常用的方式:按键排序(sort by key), 按值排序(sort by value). 1.按键排序 jdk内置的java.util包下的TreeMap<K,V>既可满足此类需求,向其构造方法 TreeMap(Comparator<? super K> comparator) 传入我们自定义的比较器即可实现按键排序. 实现代码 public class MapSortDemo { public static void ma
测试报告: Array length: 20000 bubbleSort : 573 ms bubbleSortAdvanced : 596 ms bubbleSortAdvanced2 : 583 ms selectSort : 160 ms insertSort : 76 ms insertSortAdvanced : 59 ms insertSortAdvanced2 : 164 ms binaryTreeSort : 3 ms shellSort : 2 ms shellSortAdva