Techie Notes
Wednesday, June 9, 2010
Initialization of list/map in one line
List
ArrayList
places = new ArrayList
(Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));
ArrayList
list = new ArrayList
() {{
add("A");
add("B");
add("C");
}}
link
Map
Map
m = new HashMap
() {
{
put(".jpg", "image/jpeg");
put(".jpeg", "image/jpeg");
}
};
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)