Java学习-常用类(Arrays)
程序员文章站
2024-03-05 23:35:31
...
一、输出数组元素——toString()
int[] arr1 = {1,2,3};
System.out.println(Arrays.toString(arr1));
二、比较数组元素——equals()
int[] arr1 = {1,2,3};
int[] arr2 = {1,2,3};
System.out.println(Arrays.equals(arr1,arr2));
三、升序数组元素——sort()
int[] arr1 = {1,3,2};
Arrays.sort(arr1);
System.out.println(Arrays.toString(arr1));
四、数组转集合——asList()
int[] arr1 = {1,3,2};
List<int[]> li = Arrays.sort(arr1);
System.out.println(li.get(1)); // 3