0
0

More than 1 year has passed since last update.

HashSet , TreeSet class

Last updated at Posted at 2023-02-10

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0