HashSet<String> shopping_list = new HashSet<String>() {{ add("milk"); add("peanut butter"); add("bread"); }}; // Notice the double bracebrackets
Programming Tips - Java: Nice way to initialize a HashSet
Date: 2012sep23
Language: Java
Keywords: init
Q. Java: Nice way to initialize a HashSet
A. Like this: