日期:2014-05-20 浏览次数:20670 次
import java.util.*; public class BasicContainer { public static void main(String args[]) { Collection c = new HashSet(); Name n = new Name("ye","dame"); Name m = new Name("ye","dame"); c.add(n); System.out.println(c.remove(m)); System.out.println(c); } } class Name{ String firstname; String secondname; Name(String firstname,String secondname) { this.secondname = secondname; this.firstname = firstname; } public boolean equals(Name n) { return (this.secondname.equals(n.secondname)) && (this.firstname.equals(n.firstname)); } public int hashCode() { return firstname.hashCode(); } }