Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 45
    If this is intended for unit testing, try groovy out for a swing. You can write your test code in it while testing java code, and use ArrasyList<String> places = ["Buenos Aires", "Córdoba", "La Plata"] Commented Dec 31, 2010 at 21:40
  • 5
    In Java SE 7, you can substitute the parameterized type of the constructor with an empty set of type parameters (<>): Map<String, List<String>> myMap = new HashMap<>(); Commented Jul 7, 2015 at 21:12
  • 2
    See also stackoverflow.com/questions/157944/create-arraylist-from-array Commented Oct 8, 2015 at 11:05
  • 13
    Stream.of("val1", "val2").collect(Collectors.toList()); //creates ArrayList, Java8 solution. Commented Oct 13, 2017 at 17:37
  • 8
    I don't understand why we cannot have some thing like List<Integer> = {1, 2, 3, 4, 5} in Java. Create and init a mutable array in one line, as I know Python and Swift could do that. Commented Mar 20, 2021 at 6:10