About 73,400,000 results
Open links in new tab
  1. Initializing a List in Java - GeeksforGeeks

    Apr 16, 2025 · List is an interface, and the instances of List can be created in the following ways: Example: Creating ArrayList, LinkedList, Vector and Stack using the List Interface. 1. Double Braces Initialization. We can also initialize the list using the double braces. Syntax: Example: Creating a list using the double braces initialization. 2.

  2. How to make a new List in Java - Stack Overflow

    May 13, 2009 · There is numerous way you can create and initialize array list in java. 1) List list = new ArrayList(); 2) List<type> myList = new ArrayList<>(); 3) List<type> myList = new ArrayList<type>(); 4) Using Utility class List<Integer> list = Arrays.asList(8, 4); Collections.unmodifiableList(Arrays.asList("a", "b", "c")); 5) Using static factory ...

  3. Java ArrayList - W3Schools

    Create an ArrayList object called cars that will store strings: import java.util.ArrayList; // import the ArrayList class ArrayList<String> cars = new ArrayList<String>(); // Create an ArrayList object

  4. Java ListHow To Create, Initialize & Use List In Java

    Apr 1, 2025 · This Java List Tutorial Explains How to Create, Initialize and Print Lists in Java. The tutorial also Explains List of Lists with Complete Code Example.

  5. java - How to declare an ArrayList with values? - Stack Overflow

    In Java 9+ you can use List.of to conveniently produce an unmodifiable list. Java 8 using Stream: Or, in Java 16+, more briefly done with toList: And of course, you can create a new object using the constructor that accepts a Collection: Tip: The docs contains very useful information that usually contains the answer you're looking for.

  6. How to Initialize a List in Java: 7 Step-by-Step Methods - wikiHow

    Jan 3, 2024 · In this article, we will cover 7 ways to initialize a list (or an array that looks like a list) in Java. You cannot add to a List, but you can create an array that looks like a List that can be added to later. Lists can hold various data types, such as …

  7. Java List Collection Tutorial and Examples - CodeJava.net

    Feb 10, 2025 · In this Java list tutorial, I will help you understand the characteristics of list collections, how to use list implementations (ArrayList and LinkedList) in day-to-day programming and look at various examples of common programming practices when using lists.

  8. Java List Interface - GeeksforGeeks

    Apr 8, 2025 · Using ListIterator, we can traverse the list in both forward and backward directions. Example: Lets get deep dive onto creating objects or instances in a List. List is an interface, objects cannot be created of the type list. We always need a class that implements this List in order to create an object.

  9. Java List Initialization in One Line - Baeldung

    Apr 4, 2025 · We can create a List from an array. And thanks to array literals, we can initialize them in one line: List<String> list = Arrays.asList(new String[]{"foo", "bar"}); We can trust the varargs mechanism to handle the array creation. With that, …

  10. How to Create a List in Java - JavaBeat

    Apr 30, 2024 · How to Create a List in Java. You can create a list in Java using one of the following methods: Method 1: Creating a List Using the new Operator; Method 2: Creating a List Using Arrays.asList() Method 3: Creating a List Using List.of() Method 4: Creating a List Using Stream.of() and Collectors.toList() Method 5: Creating a List Using ...

  11. Some results have been removed
Refresh