心之所愿,无事不成 Nothing is impossible to a willing heart
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
对动态数组ArrayList部分自带功能进行了实验理解import java.util.ArrayList;import java.util.Arrays;public class Demo1 {public static void main(String[] args) { ArrayList<Number> arr1 = new ArrayList<Number>();//定义一个动态数组arr1 ArrayList<Number> arr2 = new ArrayList<Number>();//定义一个动态数组arr2 arr1.add(1);arr1.add(2);arr1.add(3);arr1.add(4);arr1.add(5); arr1.add(6);arr1.add(7);arr1.add(8);arr1.add(9);arr1.add(10); arr2.add(10);arr2.add(9);arr2.add(8);arr2.add(7);arr2.add(6); arr2.add(5);arr2.add(4);arr2.add(3);arr2.add(2);arr2.add(1); System.out.println(arr1); System.out.println(arr2); 运行结果[1, 2, 3, 4, 5, 6, 7, 8, 9, 10][10, 9, 8, 7, 6, 5, 4, 3, 2, 1]int a1 = arr1.size();//获取动态数组arr1的长度 System.out.println(a1); boolean a2 = arr1.isEmpty();//检验动态数组arr1是否为空 System.out.println(a2); int a3 = arr1.indexOf(3);//获取元素数字3在动态数组arr1中的位置 System.out.println(a3); 运行结果10false2 boolean a4 = arr1.contains(3);//检验数字元素3是否存在与动态数组arr1中, boolean a5= arr1.contains(100);//检验数字元素3是否存在与动态数组arr1中 System.out.println(a4); System.out.println(a5); arr1.add(3); System.out.println(arr1); int a6 = arr1.lastIndexOf(3);//获取动态数组中最后一个数字3所在的位置 System.out.println(a6); ArrayList<Number> arr4 = (ArrayList<Number>) arr1.clone();//将动态数组arr1中所有的元素复制到动态数组arr4中 System.out.println(arr4);运行结果truefalse[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]10[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]Object[] arr3 = arr1.toArray(); System.out.println(Arrays.toString(arr3));//将动态数组arr1中的所有元素移到数组arr3(注意输出方式!!数组应用(toString输出) int a7 = (int) arr1.get(3);//输出动态数组arr1中第三位元素的值 System.out.println(a7); arr1.set(10, 11);//将动态数组arr1中的第10位元素数值改成11; System.out.println(arr1);运行结果[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]4[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] arr1.add(2, 2.5);//在动态数组的第二位怎加元素数值为2.5 System.out.println(arr1); arr1.remove(2);//移去动态数组arr1中的第2个节点 System.out.println(arr1); System.out.println(arr1); arr1.addAll(2, arr2);//将动态数组arr2中所有的节点元素插入入到动态数组arr1中的第二个位置 System.out.println(arr2); System.out.println(arr1);运行结果[1, 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11][1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11][1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11][10, 9, 8, 7, 6, 5, 4, 3, 2, 1][1, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11]arr2.clear();//清空第二个数组 System.out.println(arr2); System.out.println(arr4); System.out.println(arr1); arr1.removeAll(arr4);//将动态数组arr1中所有和动态数组arr4中相同的的节点元素去除 System.out.println(arr1); System.out.println(arr4); arr1.addAll(0,arr4); System.out.println(arr1); arr1.retainAll(arr4);//将动态数组arr1中所有动态数组arr4中没有的的节点元素去除 System.out.println(arr1); // arr1.listIterator();// arr1.iterator();// System.out.println(arr1);// System.out.println(arr1);//还需继续学习运行结果[][1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3][1, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11][11][1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3][1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11][1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]有关文件输出流输入流的只是还没有学习到,没有做出解释xxxxxxxxxx [1, 2, 100, 4, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7, 8, 9, 11, 12][1, 100, 4, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7, 8, 9, 11, 12][1, 100, 4, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 1, 7, 8, 9, 11, 12]