About 628,000 results
Open links in new tab
  1. java - Create ArrayList from array - Stack Overflow

    Oct 1, 2008 · If You Can't... For an Immutable List. Use the JDK's Arrays class and its asList() factory method, wrapped with a Collections.unmodifiableList():

  2. java - Initialization of an ArrayList in one line - Stack Overflow

    Jun 17, 2009 · Java 8 or earlier: List<String> strings = Arrays.asList("foo", "bar", "baz"); Arrays.asList(...) will give you a List * backed by an array, so it cannot change length. But you …

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

    May 13, 2009 · Ints.asList does not create an immutable list, but a fixed-size list backed by given array of ints (i.e. it supports List.set(int, Object)). Second example of "Immutable List of …

  4. java - How can I create an Array of ArrayLists? - Stack Overflow

    May 11, 2021 · You can create Array of ArrayList. List<Integer>[] outer = new List[number]; for (int i = 0; i < number; i++) { outer[i] = new ArrayList<>(); } This will be helpful in scenarios like this. …

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

    List<String> x = new ArrayList<>(Arrays.asList("xyz", "abc")); If you don't want to add new elements to the list later, you can also use (Arrays.asList returns a fixed-size list): List<String> …

  6. How do I declare and initialize an array in Java? - Stack Overflow

    Jul 29, 2009 · Static Array: Fixed size array (its size should be declared at the start and can not be changed later) Dynamic Array: No size limit is considered for this. (Pure dynamic arrays do …

  7. java - Creating an Arraylist of Objects - Stack Overflow

    Oct 20, 2010 · If you want to allow a user to add a bunch of new MyObjects to the list, you can do it with a for loop: Let's say I'm creating an ArrayList of Rectangle objects, and each Rectangle …

  8. Convert list to array in Java - Stack Overflow

    @SuZhang If the list fits in the specified array. For sure the list does not fit into the passed array new Foo[0] (unless the list itself is empty), and a new array will be created for holding the list …

  9. java - Creating a list with repeating element - Stack Overflow

    Oct 10, 2014 · List<String> asList = Arrays.asList(strArray); Then I have to use two lines: String[] strArray = new String[5]; Arrays.fill(strArray, "foo");. Is there a one-line solution? You can use …

  10. java - Initial size for the ArrayList - Stack Overflow

    Jan 17, 2012 · I faced with the similar issue, and just knowing the arrayList is a resizable-array implementation of the List interface, I also expect you can add element to any point, but at …

Refresh