How to initialize a HashSet in Java

1 Answer

0 votes
import java.util.*;

public class MyClass {
    public static void main(String args[]) {
      Set<String> letters = new HashSet<>(Arrays.asList("a", "b", "c", "d", "a", "a"));

      System.out.println(letters);
    }
}




/*
run:

[a, b, c, d]

*/

 



answered Feb 16, 2021 by avibootz

Related questions

2 answers 140 views
1 answer 128 views
1 answer 173 views
1 answer 138 views
138 views asked Jul 18, 2022 by avibootz
1 answer 140 views
140 views asked Jul 18, 2022 by avibootz
2 answers 236 views
2 answers 157 views
...