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 255 views
1 answer 212 views
1 answer 255 views
1 answer 221 views
221 views asked Jul 18, 2022 by avibootz
1 answer 230 views
230 views asked Jul 18, 2022 by avibootz
2 answers 347 views
2 answers 288 views
...