Collection 接口 中 的 remove方法 接收的是 元素,List 集合中的 remove 方法接收的是索引
常见的 List 集合
ArrayList、LinkedList
特点
ArrayList...值相同 不会覆盖
System.out.println(collection.size()); // 5
collection.remove("张4");...值相同 不会覆盖
list.forEach(a -> System.out.print(a+",")); // 张1,张2,张3,张4,张1,
// 替换元素...数组 从0 开始 替换 索引下标为1 的 元素 即 0 1 是第二个元素 故 张2 被替换
list.set(1,"我被替换了");
System.out.println...(a+",")); // 张1,我被替换了,张3,张1,
}
特殊说明:
解决问题的光鲜,藏着磕Bug的痛苦。