HashSet add, remove
import java.util.HashSet; import java.util.Set; import java.util.TreeSet; public class Sets { public static void main(String[] args) { // TODO Auto-generated method stub Person p1 = new Person("320321"); p1.setAge(22); p1.setName("p1"); Person p2 = new Person("320321"); p2.setAge(23); p2.setName("p2"); Person p3 = new Person("320322"); p3.setAge(22); p3.setName("p3"); Person p4=new Person("320321"); p4.setAge(22); p4.setName("p4"); Set<Person> hashSet = new HashSet(); hashSet.add(p1); hashSet.add(p2); // System.out.println(hashSet); hashSet.add(p3); // System.out.println(hashSet); hashSet.add(p4); // System.out.println(hashSet); } }
时间: 2024-10-12 19:15:14