@Test public void test02() { List of = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6)); //输出集合 --> [1, 2, 3, 4, 5, 6] System.out.println(of); //给原集合增加一个元素7 --> [1, 2, 3, 4, 5, 6, 7] of.add(7); System.out.println(of); //将该集合下标为2的元素修改为30 --> [1, 2, 30, 4, 5, 6, 7] of.set(2, 30); System.out.println(of); //删除该集合下标为1的元素 --> [1, 30, 4, 5, 6, 7] of.remove(1); System.out.println(of); //增加该集合下标为3的元素为20 --> [1, 30, 4, 20, 5, 6, 7] of.add(3, 20); System.out.println(of); //查询该集合下标为2的元素的值为 --> 4 System.out.println(of.get(2)); }
上一篇 java8 stream流求和计算
下一篇 字节跳动社招Java常见面试题
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号