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 147 views
1 answer 132 views
1 answer 176 views
1 answer 144 views
144 views asked Jul 18, 2022 by avibootz
1 answer 148 views
148 views asked Jul 18, 2022 by avibootz
2 answers 242 views
2 answers 166 views
...