Explain ArrayList and difference between ArrayList and Vector?

Explain ArrayList and difference between ArrayList and Vector?

Explain ArrayList and difference between ArrayList and Vector?

Explain ArrayList and difference between ArrayList and Vector?
  • ArrayList is a class, that uses a dynamic array for storing the elements. It extends AbstractList class and implements List interface.
  • The underlying data structure is a Resizable array or growable array.
  • Duplicates are allowed.
  • Insertion order is preserved.
  • Heterogeneous objects are allowed(except TreeSet and TreeMap everywhere Heterogeneous objects are allowed)
  • Null insertion is possible.
  • Manipulation slows because a lot of shifting needs to occur if any element is removed from the array list.
  • Usually, we can use the collection to hold and transfer objects from one location to another location (container) to provide support for this requirement every collection class by default implements Serialization and Cloneable interface.
  • ArrayList and vector classes implement the RandomAccess interface so that any random element we can access with the same speed.
  • ArrayList is a data structure that can be stretched to accommodate additional elements within itself and shrink back to a smaller size when elements are removed. It is a very important data structure useful in handling the dynamic behavior of elements.

Constructors in ArrayList

1 ArrayList l=new ArrayList()
  1. Creates an empty ArrayList object with default initial capacity 10.
  2. once ArrayList reaches its max capacity then a new ArrayList object will be created with
    New capacity=(current capacity*3/2)+1
2 ArrayList l=new ArrayList(int initial capacity)
  1. Creates an empty ArrayList object with specified initial capacity.
3 ArrayList l=new ArrayList(Collection c)
  1. Creates an equivalent ArrayList object for the given collection.

Leave a Reply

Your email address will not be published. Required fields are marked *

*