Last active
August 29, 2015 14:27
-
-
Save yuki2006/ba19faaa0ea57b03b933 to your computer and use it in GitHub Desktop.
JavaでListの要素を初期化・追加する方法 ref: http://qiita.com/yuki2006/items/be1433c50002cc24603b
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
List<String> list = Arrays.asList("AA", "BB", "CC"); | |
// UnsupportedOperationExceptionが発生する | |
list.add("DD"); | |
list.remove(0); |
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
List<String> list = new ArrayList<String>(); | |
Collections.addAll(list, "AA", "BB", "CC"); |
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
List<String> list = new ArrayList<>(); | |
list.addAll(Arrays.asList("AA", "BB", "CC")); | |
list.add("DD"); | |
list.remove(0); |
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
List<String> list = new ArrayList<>(); | |
list.addAll(Arrays.asList("AA", "BB", "CC")); | |
list.add("DD"); | |
list.remove(0); |
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
List<String> list = new ArrayList<>(); | |
list.addAll(Arrays.asList("AA", "BB", "CC")); | |
list.add("DD"); | |
list.remove(0); |
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
List<String> list = Collections.synchronizedList(new ArrayList<String>()); | |
list.addAll(Arrays.asList("AA", "BB", "CC")); |
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
List<String> list = new ArrayList<>(); | |
for (String item : new String[]{"AA", "BB", "CC"}) { | |
list.add(item); | |
} |
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
List<String> list = new ArrayList<>(); | |
list.add("AA"); | |
list.add("BB"); | |
list.add("CC"); |
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
List<String> list = new ArrayList<String>(){ | |
{ | |
add("AA"); | |
add("BB"); | |
add("CC"); | |
} | |
}; |
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
List<String> list = new ArrayList<>(Arrays.asList("AA", "BB", "CC")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment