About 203,000 results
Open links in new tab
  1. What is the difference between List and Array in Java?

    Apr 25, 2024 · In general (and in Java) an array is a data structure consisting of sequential memory storing a collection of objects. List is an interface in Java, which means that it may have multiple implementations. One of these implementations is ArrayList, which is a class that implements the behavior of the List interface using arrays as the data structure.

  2. Array or List in Java. Which is faster? - Stack Overflow

    Apr 4, 2009 · Array vs. List choice is not so important (considering performance) in the case of storing string objects. Because both array and list will store string object references, not the actual objects. If the number of strings is almost constant then use an array (or ArrayList). But if the number varies too much then you'd better use LinkedList.

  3. When to use a List over an Array in Java? - Stack Overflow

    Oct 19, 2009 · There are almost no good reason to use an array instead of List. The main exception being the primitive array (like int[]). You cannot create a primitive list (must have List<Integer>). The most important difference is that when using List you can decide what implementation will be used. The most obvious is to chose LinkedList or ArrayList.

  4. java - How do I know whether to use an array or an arraylist?

    Jul 21, 2014 · While Array can contain both primitives and Objects in Java. Though Autoboxing of Java 5 may give you an impression of storing primitives in ArrayList, it actually automatically converts primitives to Object. Java provides add() method to insert element into ArrayList and you can simply use assignment operator to store element into Array e.g ...

  5. java - what is the difference between a list and an arraylist

    Sep 4, 2012 · Adding can also be done in constant time, if the array has been allocated with enough space. However, when the space runs out, ArrayList will allocate a larger array and copy the old array values into the new one. A LinkedList uses nodes that are chained together. Accessing by an index can potentially require walking the entire list (linear time).

  6. Type List vs type ArrayList in Java - Stack Overflow

    Feb 17, 2010 · When you write ArrayList, you specify that your object class is a resizable-array. So, the first version makes your code more flexible in future. Look at Java docs: Class ArrayList - Resizable-array implementation of the List interface. Interface List - An ordered collection (also known as a sequence). The user of this interface has precise ...

  7. java - Array vs ArrayList in performance - Stack Overflow

    Oct 16, 2013 · For simple accesses and set operations the [] array will outperform the List by roughly a factor of 2-4. But that's multiplying times a very small amount of time. But if you ever need to resize the array or do something else more complex than simple set/access the List form will be quite a bit more convenient and likely a bit better performer.

  8. What is the difference between an Array, ArrayList and a List?

    Also, System.Array supports multiple dimensions (i.e. it has a Rank property) while List and ArrayList do not (although you can create a List of Lists or an ArrayList of ArrayLists, if you want to). An ArrayList is a flexible array which contains a list of objects.

  9. java - Are there reasons to prefer Arrays over ArrayLists ... - Stack ...

    May 12, 2014 · sorting List (via j.u.Collections) are first transformed to [], then sorted (which clones the [] once again for the merge sort) and then put back to List. You do understand that ArrayList has a backing Object[] under the cover. Back in the day there was a case ArrayList.get was not inlined by -client hotspot compiler but now I think that's fixed.

  10. When to use LinkedList over ArrayList in Java? - Stack Overflow

    An array list is essentially an array with methods to add items etc. (and you should use a generic list instead). It is a collection of items which can be accessed through an indexer (for example [0]). It implies a progression from one item to the next. A linked list specifies a progression from one item to the next (Item a -> item b).

Refresh