开发中经常用到Arrays和Collections这两个工具类. 在数组和列表之间进行切换.非常方便.但是也会遇到一些问题. 看代码: import java.util.Arrays; import java.util.List; public class Client { public static void main(String[] args) { int[] data = {1,2,3,4,5}; List list = Arrays.asList(data); System.out.p…
Similarities:Both are custom ways to compare two objects.Both return an int describing the relationship between two objects. Differences: Comparator compare() is from the Comparator interface. A comparator object is capable of comparing two differe…
在调用Arrays.sort()对数组进行排序时,默认是升序排序的,如果想让数组降序排序,有下面两种方法: 利用Collections的reverseOrder import java.util.*; public class Main { public static void main(String[] args) { // 注意这里是Integer,不是int Integer[] arr={9,8,7,6,5,4,3,2,1}; Arrays.sort(arr,Collections.rev…