How can I create a Set in java, and then add objects to it when it is constructed. I want to do something like:
testCollision(getObject(), new HashSet<MazeState>(){add(thing);});
But that doesn’t seem quite right.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Java 5
Arrays.asList(thing)converts yourthingto the list of one element, and from that list set is created.For the reference:
http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList(T…)