1.数组
1.1 数组初始化
String[] Array = new String[5];
String[] Array = {"a","b","c", "d", "e"};
String[] Array = new String[]{"a","b","c","d","e"};
1.2 数组添加/更改某个元素
Array[0] = "g";
1.3 数组打印
System.out.print(Arrays.toString(Array)); //直接打印只能打印出地址
1.4 数组排序
Arrays.sort(Array); //底层是快排
1.5 数组反转
ArrayUtils.reverse(Array);
1.6 二维数组
int[][] arr = new int[m][n];
int[][] arr = {{1,2,3},{4,5,6},{7,8,9}};
2. 数组链表---ArrayList
2.1 初始化
ArrayList<String> arrayList = new ArrayList<String>();
ArrayList<String> arrayList = new ArrayList<String>(16); //指定长度
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(String "a",String "b", String "c"));
2.2 根据数组创建
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(Array));
2.3 转为数组
String[] Array = arraylist.toArray(new String[arrayList.size()]);
2.4 添加元素
arrayList.add("a");
arrayList.add(2,"b"); //添加元素到指定位置
2.5 获取某元素
String str = arrayList.get(0);
2.6 找出某元素的位置
int index = arrayList.indexOf("b");
2.7 替换某位置的元素
arrayList.set(1, "k");
2.8 移除某元素
arrayList.remove(0);
arrayList.remove("d"); //只删除第一次出现的
2.9 检查是否为空
boolean bool = arrayList.isEmpty();
2.10 获取长度
int length = arrayList.size();
2.11 遍历
for (int i = 0; i < arrayList.size(); i++) {
System.out.println(arrayList.get(i));
}
for(String str : arrayList){
System.out.println(str);
}
2.12 二维数组
List<List<Integer>> arr = new ArrayList<List<Integer>>();