1.打印数组内容
Arrays.toString(arr)
public static void main(String[] args) {
int[] arr1 = new int[3];
int[] arr2 = new int[5];
Arrays.fill(arr1,11);
Arrays.fill(arr2,22);
System.out.println("arr1 = [" + Arrays.toString(arr1) + "]");
System.out.println("arr2 = [" + Arrays.toString(arr2) + "]");
}
输出结果:
arr1 = [[11, 11, 11]]
arr2 = [[22, 22, 22, 22, 22]]
public static void main(String[] args) {
int[] arr1 = new int[3];
int[] arr2 = new int[5];
int[] arr3 = new int[5];
Arrays.fill(arr1,11);
Arrays.fill(arr2,22);
Arrays.fill(arr3,22);
System.out.println("arr1==arr2 ["+ Arrays.equals(arr1,arr2)+"]");
System.out.println("arr2==arr3 ["+ Arrays.equals(arr2,arr3)+"]");
}
输出结果:
arr1==arr2 [false]
arr2==arr3 [true]
public static void main(String[] args) {
int[] arr1 = {1,3,2};
String[] arr2 = {"a","bc","aa","ss"};
Arrays.sort(arr1);
Arrays.sort(arr2);
System.out.println("arr1 = [" + Arrays.toString(arr1) + "]");
System.out.println("arr2 = [" + Arrays.toString(arr2) + "]");
}
输出结果:
arr1 = [[1, 2, 3]]
arr2 = [[a, aa, bc, ss]]
public static void main(String[] args) {
String[] arr1 = {"1","3","2"};
String[] arr2 = {"a","bc","aa","ss"};
Arrays.sort(arr1);
Arrays.sort(arr2);
System.arraycopy(arr1,0,arr2,1,2);
System.out.println("arr1 = [" + Arrays.toString(arr1) + "]");
System.out.println("arr2 = [" + Arrays.toString(arr2) + "]");
}
输出结果:
arr1 = [[1, 2, 3]]
arr2 = [[a, 1, 2, ss]]
public static void main(String[] args) {
String[] arr1 = {"1","3","2"};
String str = "a,b,c,d";
List list = Arrays.asList(arr1);
List listStr = Arrays.asList(str);
System.out.println("list = [" + list. + "]");
System.out.println("listStr = [" + listStr + "]");
}