About 55,900 results
Open links in new tab
  1. 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> …

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

    Jun 17, 2009 · * Implementation detail: It's a private nested class inside java.util.Arrays, named ArrayList, which is a different class from java.util.ArrayList, even though their simple names …

  3. java - Initializing ArrayList with some predefined values - Stack …

    Apr 24, 2013 · You can also use the varargs syntax to make your code cleaner: Use the overloaded constructor: ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", …

  4. How can I initialize an ArrayList with all zeroes in Java?

    The integer passed to the constructor represents its initial capacity, i.e., the number of elements it can hold before it needs to resize its internal array (and has nothing to do with the initial …

  5. java - ArrayList initialization equivalent to array initialization ...

    The list returned by Arrays.asList() is NOT unmodifiable, @kocko. It has a fixed size, but you can change the references to point to entirely different objects like Arrays.asList(...).set(0,new …

  6. Java - ArrayList default initial values - Stack Overflow

    Oct 11, 2015 · ArrayLists have no default values. If you give the ArrayList a initialCapacity at initialization, you're just giving a hint for the size of the underlying array—but you can't actually …

  7. Directly setting values for an ArrayList in Java - Stack Overflow

    Jan 21, 2011 · that's true, but i'd only take it to heart if you plan on re-using the class. anonymous classes are for inline convenience not reuse. or, another way to look at it ... i'm creating a new …

  8. java - Create ArrayList from array - Stack Overflow

    Oct 1, 2008 · So, you might initialize arraylist like this: List<Element> arraylist = Arrays.asList(new Element(1), new Element(2), new Element(3)); Note: each new Element(int args) will be …

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

    Jan 17, 2012 · Capacity of an ArrayList isn't the same as its size. Size is equal to the number of elements contained in the ArrayList (and any other List implementation). The capacity is just …

  10. How to initialize 2D ArrayList in Java? - Stack Overflow

    If it is not necessary for the inner lists to be specifically ArrayLists, one way of doing such initialization in Java 7 would be as follows:

Refresh