Created
December 18, 2014 20:03
-
-
Save Bachmann1234/3fc0efd8a245e95bb438 to your computer and use it in GitHub Desktop.
Statically initialized map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public class Test { | |
public static void main(String[] args) { | |
Map<Integer, String> tens = new HashMap<Integer, String>(){{ | |
put(10, "ten"); | |
put(20, "twenty"); | |
put(30, "thirty"); | |
put(40, "fourty"); | |
put(50, "fifty"); | |
put(60, "sixty"); | |
}}; | |
System.out.println(tens.get(10)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Technically you don't need the
java.util.Map;
import since you're not using thisHashMap
as aMap
elsewhere. ;)