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

    Jun 17, 2009 · ArrayList<String> list = new ArrayList<String>() {{ add("A"); add("B"); add("C"); }}; However, I'm not too fond of that method because what you end up with is a subclass of ArrayList …

  2. Creating a new ArrayList in Java - Stack Overflow

    Assuming that I have a class named Class, And I would like to make a new ArrayList that it's values will be of type Class. My question is that: How do I do that? I can't understand from Java Api...

  3. java - Create ArrayList from array - Stack Overflow

    Oct 1, 2008 · So, if you want to be able to add or remove elements from the returned list in your code, you'll need to wrap it in a new ArrayList. Otherwise you'll get an UnsupportedOperationException. …

  4. How to quickly and conveniently create a one element arraylist

    Variable size List If it needs vary in size you can construct an ArrayList and the fixed-size List like return new ArrayList<String>(Arrays.asList(s)); and (in Java 7+) you can use the diamond operator <> to …

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

    Closed 9 years ago. ArrayList or List declaration in Java has questioned and answered how to declare an empty ArrayList but how do I declare an ArrayList with values? I've tried the following but it returns …

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

    May 13, 2009 · List<String> list = new ArrayList<>(); This is how to create a LinkedList in java, If you need to do frequent insertion/deletion of elements on the list, you should use LinkedList instead of …

  7. java - Create mutable List from array? - Stack Overflow

    0 new ArrayList <> ( List.of ( arr ) ) List.of In Java 9 +, you can: Pass an array to List.of to create an unmodifiable List collection. Then pass that resulting list to the constructor of a modifiable List …

  8. How to create ArrayList (ArrayList<Integer>) from array (int[]) in Java

    Jul 8, 2013 · intList = new ArrayList<Integer>(Arrays.asList(intArray)); From your comment: if you want to still use an int[] (or another primitive type array) as main data, then you need to create an …

  9. How to create an 2D ArrayList in java? - Stack Overflow

    Jun 6, 2013 · 61 I want to create a 2D array that each cell is an ArrayList! If you want to create a 2D array of ArrayList.Then you can do this :

  10. java - ArrayList of Characters - Stack Overflow

    Jul 13, 2014 · I want to create an ArrayList of character objects based off the characters in a string of letters. But, I can't seem to figure out how to fill that ArrayList to match the String.