Java的Set类 Li.038
Set 无序 不可重复 import java.util.HashSet; public class Demo1_HashSet { public static void main(String[] args) { HashSet<String> hs = new HashSet<>(); boolean b1 = hs.add("a"); boolean b2 = hs.add("a"); System.out.println(hs); System.out.println(b1+" "+b2); for(String s:hs){ System.out.println(s); } } } HashSet 的重写hashCode() 方法, hashCode值一致时, 调用equals方法 使用HashSet 存取元素时, 这个元素必须重写 hashCode 和 equals方法 import lombok.Getter; import lombok.Setter; import java.util.Objects; public class Person { public Person(){} public Person(String name, int age){ this.name = name; this.age = age; } @Getter @Setter private String name; @Getter @Setter private int age; @Override public String toString(){ return "Person" + this....