Created
May 15, 2010 02:36
-
-
Save akishin/401951 to your computer and use it in GitHub Desktop.
This file contains 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
// java.util.List の初期化を一行で書く | |
List<String> list = new ArrayList<String>() {{add("a"); add("b"); add("c");}}; | |
// 変更不可能な List で良い場合は | |
List list = Arrays.asList("a", "b", "c"); | |
// Arrays.asList をジェネリックスを使って書くと | |
List<Integer> list = Arrays.<Integer>asList(1, 2, 3); | |
// asList を使いつつ、追加可能な List を作るには、冗長だが以下のようにする | |
List<Integer> list = new ArrayList<Integer>(Arrays.<Integer>asList(1, 2, 3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment