About 14,800,000 results
Open links in new tab
  1. How to Create an Empty ArrayList in Java? - Tutorial Kart

    To create an Empty ArrayList in Java, you can use new keyword and ArrayList constructor with no arguments passed to it. Following is the syntax to create an empty ArrayList. Copy

  2. Java Program to Empty an ArrayList in Java - GeeksforGeeks

    Dec 14, 2021 · Method 1: Using clear() method as the clear() method of ArrayList in Java is used to remove all the elements from an ArrayList. The ArrayList will be completely empty after this …

  3. java - How do I set an empty list of a certain type - Stack Overflow

    Mar 29, 2011 · Hence, you can use the following statement to create an empty list: var list = List.of() // since Java 10, use the var keyword, List.of() was introduced in Java 9. Since Java 9: …

  4. 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 …

  5. Java ArrayList – How To Declare, Initialize & Print An ArrayList

    Apr 1, 2025 · The ArrayList class in Java provides the following constructor methods to create the ArrayList. Method #1: ArrayList() This method uses the default constructor of the ArrayList …

  6. Java Create Empty Lists: A Step-by-Step Guide | by Rahul - Medium

    May 3, 2024 · ArrayList is a commonly used implementation of the List interface in Java. To create an empty ArrayList, follow these simple steps: By declaring a variable of type List and …

  7. Initialize an ArrayList in Java - HowToDoInJava

    Aug 4, 2023 · We initialize an empty ArrayList (with the default initial capacity of 10) using the no-argument constructor and add elements to the list using add () method. Optionally, the …

  8. How do I represent an empty list in java? - Stack Overflow

    Jul 10, 2016 · To represent an Empty List in Java (an ArrayList is a List), we use java.util.Collections.emptyList(). So you could use something like this: Foo foo = new …

  9. Initialize an ArrayList with Zeroes or Null in Java - Baeldung

    Mar 7, 2025 · In this tutorial, we’ll explore different ways to initialize a Java ArrayList with all values null or zero. We can also play with the initializations as we like and initialize the lists …

  10. 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"); …