1、remove(int index);//删除指定位置的元素
2、remove(Object o);//删除指定对象,考查删除对象的规则是什么?
3、removeAll(Collection col);//删除指定集合中的所有元素。
4、contains(Object o);//是否包含
5、contains(Collection col);//是否包含集合。
public class Demo {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// Trianle t = new Trianle(1, 2, 3);
// t.chech();
List<Student> lt = new ArrayList<Student>();
lt.add(new Student("a", 1, 1000));
lt.add(new Student("b", 2, 2000));
lt.add(new Student("c", 3, 3000));
lt.add(new Student("d", 4, 4000));
lt.add(new Student("e", 5, 5000));
lt.add(new Student(null, 6, 6000));
// for (Student student : lt) {
// System.out.println(student.getName() + student.getAge());
// }
Iterator<Student> it1 = lt.iterator();
//Student ss = lt.remove(2);
Iterator<Student> it = lt.iterator();
//System.out.println(ss.getName() + "\n\n");
List<Student> lt2 = new ArrayList<Student>();
lt2.add(new Student("a", 1, 1000));
lt2.add(new Student("b", 2, 2000));
lt2.add(new Student("c", 3, 3000));
//System.out.println(lt.remove(new Student("a", 1, 1000)));
System.out.println(lt.contains(new Student(null, 6, 6000)));
System.out.println(lt.containsAll(lt2));
it = lt.iterator();
while(it.hasNext()) {
System.out.println(it.next().getName());
}
}
}
package com.cn;
public class Student {
private String name;
private int age;
private int phone;
public Student(String name, int age, int phone) {
super();
this.name = name;
this.age = age;
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (obj.getClass() == Student.class) {
Student st = (Student) obj;
if (this.name == st.getName() && this.age == st.getAge() && this.phone == st.getPhone()) {
return true;
}
}
return false;
}
}