I believe you can add objects use list.add(); However, is there an alternative way of making an ArrayList of strings? Something like ArrayList("heyey","hgfhgfh","fhfghgf") ?
Asked
Active
Viewed 777 times
2 Answers
2
List<String> listString = Arrays.asList(new String[] {"heyey","hgfhgfh","fhfghgf"});
With listString being a fixed size list (see Arrays.asList).
If you need a variable size list:
List<String> listString = new ArrayList<String<(Arrays.asList(new String[] {"heyey","hgfhgfh","fhfghgf"}));

jalopaba
- 8,039
- 2
- 44
- 57
1
List<String> strings = Arrays.asList("ohai", "I", "have", "varargs");
Or if you're kickin' it old school:
List strings = new ArrayList() {{
add("ohai");
add("Java 1.4");
add("lives");
}};

Dave Newton
- 158,873
- 26
- 254
- 302