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 261 views
1 answer 219 views
1 answer 263 views
1 answer 227 views
227 views asked Jul 18, 2022 by avibootz
1 answer 237 views
237 views asked Jul 18, 2022 by avibootz
2 answers 354 views
2 answers 295 views
...