2

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") ?

1

2 Answers 2

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"}));
Sign up to request clarification or add additional context in comments.

Comments

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");
}};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.