0
How to convert values to HashSet directly
I'm making a constructor that takes a HashSet as a parameter. How would you pass values directly on the constructor? E.g. ``` class A { A(int x, HashSet<int> y) {} } A a = new A(5, /*how to pass 6 and 7 directly?*/); ```
2 odpowiedzi
+ 1
~ swim ~ (not available on messanger) Thanks for making it clear that you can only pass objects in a HashSet. I didn't know that.
Actually I've found another answer.
A a = new A(5, new HashSet<>(Arrays.asList(6, 7)));
My goal was just to make it so that you don't have to declare a collection.
Thanks for your answer