pasobmillionaire.blogg.se

When would you use array vs arraylist java
When would you use array vs arraylist java










when would you use array vs arraylist java

One of the standard Collection classes is ArrayList which extends AbstractList class and also implements the List interface. It becomes convenient to operate on the sublist instead of a list. You can also get the sublist from the list using a method sublist(). You can set the value of an element in the list using set() method. You can obtain an element from the list using get() method. When one object in a list is incompatible with another object in the list, then ClassCastException is thrown.Null elements are not allowed in the list if you try to insert a null object in the list, NullPointerException is thrown. Methods inside the list may throw an exception like UnsupportedOperationException if the method is unable to modify the list. These methods add an element to the list by their index. The methods added by the List interface are, add(int, E) and addAll(int, Collection). In addition to the methods inherited by Collection framework, List interface also defines some method of its own.

when would you use array vs arraylist java

A list created using List interface start with a zero based index. You can access an element in the list by its position (index) in the list. List interface has elements that are associated with their index numbers. List interface is implemented by the following standard collection classes like ArrayList, LinkedList, CopyOnWriteArrayList, Vector, Stack. List interface describes the collection of elements that are arranged sequentially. List is an interface which extends the Collection framework.












When would you use array vs arraylist java