About 1,020,000 results
Open links in new tab
  1. java - Initialization of an ArrayList in one line - Stack Overflow

    Jun 17, 2009 · If you specifically need a java.util.ArrayList * If you want to both prepopulate an ArrayList and add to it afterwards, use. List<String> strings = new ArrayList<>(List.of("foo", …

  2. Initialize an ArrayList in Java - GeeksforGeeks

    Apr 7, 2025 · Below are the various methods to initialize an ArrayList in Java. 1. Initialization with add() Syntax: ArrayList<Type> al= new ArrayList<Type>(); al.add("Geeks"); al.add("for"); …

  3. Initialize an ArrayList in Java - HowToDoInJava

    Aug 4, 2023 · Java ArrayList can be initialized in one line using List.of(), and new ArrayList constructors. Learn to add elements one by one and in bulk.

  4. Add Multiple Items to an Java ArrayList - Baeldung

    Jan 8, 2024 · In this quick tutorial, we’ll show to how to add multiple items to an already initialized ArrayList. For an introduction to the use of the ArrayList, please refer to this article here. 2. …

  5. How to Initialize an ArrayList in Java - BeginnersBook

    Jun 11, 2024 · You can initialize an ArrayList with elements using Arrays.asList(). In this methods, all elements can be specified inside asList() method as shown below. However you can add …

  6. Initialize an ArrayList in Java: Easy and Advanced Methods

    Oct 26, 2023 · We began with the basics, learning how to initialize an ArrayList using the ‘new’ keyword and the ‘ArrayList’ constructor. We then advanced to intermediate techniques, …

  7. Java ArrayList - W3Schools

    For example, to add elements to the list, use the add() method: cars.add("Volvo"); . cars.add("BMW"); . cars.add("Ford"); . cars.add("Mazda"); System.out.println(cars); } } You …

  8. How to Initialize an ArrayList in Java – Declaration with Values

    Apr 21, 2023 · Alternatively, you can create an ArrayList with values/elements at the point of declaration by using the add method in an initializer block: You can use the add() method to …

  9. Add multiple items to an already initialized arraylist in Java

    Alternatively, if you will always add the same elements to the list you could create a new list that is initialized to contain all your values and use the addAll() method, with something like Integer[] …

  10. How to Add Element in Java ArrayList? - GeeksforGeeks

    Apr 3, 2023 · Element can be added in Java ArrayList using add () method of java.util.ArrayList class. 1. boolean add(Object element): The element passed as a parameter gets inserted at …