Collections in Java

On Social Media

  • provides readymade architecture.
  • represents set of classes and interface.
  • is optional.
  • Interfaces and its implementations i.e. classes
  • Algorithm
Collection Framework

Java – The List Interface

A List Collection
  • ArrayList : An implementation that stores elements in a backing array. The array’s size will be automatically expanded if there isn’t enough room when adding new elements into the list. It’s possible to set the default size by specifying an initial capacity when creating a new ArrayList.
  • LinkedList : An implementation that stores elements in a doubly-linked list data structure. It offers constant time for adding and removing elements at the end of the list; and linear time for operations at other positions in the list. Therefore, we can consider using a LinkedList if fast adding and removing elements at the end of the list is required.
Inheritance tree of List collections
WhatsApp Image 2024-07-11 at 08.28.57
  • Java ArrayList class can contain duplicate elements.
  • Java ArrayList class maintains insertion order.
  • Java ArrayList class is non synchronized.
  • Java ArrayList allows random access because array works at the index basis.
  • In Java ArrayList class, manipulation is slow because a lot of shifting needs to be occurred if any element is removed from the array list.
  • Java LinkedList class can contain duplicate elements.
  • Java LinkedList class maintains insertion order.
  • Java LinkedList class is non synchronized.
  • In Java LinkedList class, manipulation is fast because no shifting needs to be occurred.
  • Java LinkedList class can be used as list, stack or queue.
Doubly LinkedList class
map-interface
  • Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key.
  • Several methods throw a NoSuchElementException when no items exist in the invoking map.
  • A ClassCastException is thrown when an object is incompatible with the elements in a map.
  • A NullPointerException is thrown if an attempt is made to use a null object and null is not allowed in the map.
  • An UnsupportedOperationException is thrown when an attempt is made to change an unmodifiable map.
WhatsApp Image 2024-07-11 at 08.59.01

On Social Media

Leave a Reply

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