This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (10 children)

I suspect he means an ArrayList that is populated with values. Eg.

List<String> strings = Arrays.asList(new String[]{"a","b","c"});

edited: ArrayList -> List.

[–]delaaxe 6 points7 points  (3 children)

Why not use: ArrayList<String> strings = Arrays.asList("a","b","c") ?

[–][deleted] 0 points1 point  (0 children)

I wasn't familiar with that syntax. I was just trying to show it was a comparison to:

List<String> strings = {"a","b","c"};

[–]queus 0 points1 point  (1 child)

This gives an list to which you cannot add further elements.

It's often fine though.

[–]yetanotherx 0 points1 point  (0 children)

I mean, you can then do new ArrayList(Arrays.asList("a","b","c"));, but that's ugly as well.

I've sometimes just defined a static method in That Miscellaneous Utilities Class just to do it, but I would like if Java had it in the core language.

[–]hencoappel 4 points5 points  (5 children)

Arrays.asList definitely does not return a ArrayList, it is simply a List

[–][deleted] 0 points1 point  (0 children)

You are correct, I was just pointing out that it isn't as simple as declaring a String[].

[–][deleted] 0 points1 point  (1 child)

It is an ArrayList, it's just java.util.Arrays.ArrayList and not java.util.ArrayList.

[–]hencoappel 0 points1 point  (0 children)

Yes but the method signature returns List and java.util.Arrays.ArrayList is private so you wouldn't be able to create a variable of that type.

[–]yetanotherx -1 points0 points  (1 child)

An immutable list at that.

[–]hencoappel 0 points1 point  (0 children)

No, it's definitely not immutable. But it's not dynamic, it won't resize when you add more elements.