数组的常用方法
import java.util.ArrayList;
import java.util.Arrays;
public class array_Methods {
public static void main(String[] args){
Integer[] arr1 = {3,4,1,5,7,8,9,2,6};
//数组转换为列表存储
//泛型只能是引用类型,所以ArrayList不支持int类型
ArrayList<Integer> arrList = new ArrayList<Integer>(Arrays.asList(arr1));
System.out.println(arrList);
//数组转字符串
System.out.println(Arrays.toString(arr1));
//数组排序
Arrays.sort(arr1);
System.out.println(Arrays.toString(arr1));
//数组填充
Arrays.fill(arr1,8,9,0);
System.out.println(Arrays.toString(arr1));
//数组拷贝
Integer[] arr2 = Arrays.copyOf(arr1,9);
System.out.println(Arrays.toString(arr2));
}
}
路漫漫其修远兮,吾将上下而求索