All Superinterfaces:
Collection<E>, Iterable<E>
All Known Implementing Classes:
AbstractList, AbstractSequentialList, ArrayList, AttributeList,
CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector
public class test {
public static void main(String args[]) throws Exception {
List<Book> all = new ArrayList<Book>();
all.add(new Book("java开发",34.5));
all.add(new Book("jsp开发",54.5));
all.add(new Book("Oracle开发",78.5));
all.remove(new Book("Oracle开发",78.5));//需要重写equals方法
System.out.println(all);
}
}
class Book{
private String title;
private double price;
public Book(String title, double price) {
this.title = title;
this.price = price;
}
@Override
public boolean equals(Object obj) {
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(!(obj instanceof Book)){
return false;
}
Book book = (Book) obj;
if(this.title.equals(book.title)&&this.price==book.price){
return true;
}
return false;
}
@Override
public String toString() {
return "Book{" +
"title='" + title + '\'' +
", price=" + price +
'}';
}
}