Setは重複値を許容しない
HashSetは並び替えなし。以下の例では並び変わっているように見えるが、偶然
TreeSetは並び替えあり
public class Outer {
public static void main(String args[]) {
Set<String> hs = new HashSet<>();
hs.add("Z");
hs.add("C");
hs.add("V");
hs.add("B");
hs.add("A");
hs.forEach(System.out::println);
Supplier s = () -> {System.out.println("-----");return null;};
s.get();
Set<String> ts = new TreeSet<>();
ts.add("Z");
ts.add("D");
ts.add("V");
ts.add("Z");
ts.add("A");
ts.forEach(System.out::println);
}
}
A
B
C
V
Z
-----
A
D
V
Z