Collection Framework Introduction

Published: Last Updated on 1.8K views 4 minutes read
A+A-
Reset

In many procedural languages Arrays are used as variable to represent many values. Arrays are also used to store group of objects in Java programming language but there are few problems with array.

Problems with Java Array

  1. . Arrays are fixed in size so when the number of element is not known in advance then array is not suitable.
  2. Arrays can hold objects of same class only(Homogeneous objects). So we can not store object or values of different types.
  3. No underlying standard data structures so we cannot utilize predefined methods. It increase programming complexity.
array vs Collection
Difference between Array and Collection

To overcome these problems collection concept evolved. Java provide rich API of collection.
If we want to represent a group of individual objects as a single entity than we can use collection. In short Collection is group of objects. Collection framework consist of number of classes and interfaces which are used to represent group of individual objects as single entity. This is similar concept like Container and STL(Standard Template Library) in c++. Array can also be defined in terms of collection.
Array are indexed collection of fixed number of homogeneous data elements.

Interfaces in collection Framework:

Interfaces in Collection Framework are used to represent abstract behavior of different types of collection. There are about 15 interfaces contained in java.util package. The java.util.Collection is top level interface of collection Framework, means all other interfaces of Collection Framework inherit Collection interface. Let’s have a look at list of all interfaces in collection framework.

Collection Framework Introduction
Collection Framework Introduction 1
Collection API
Interfaces in Collection framework
  1. Iterable: It creates iterator for collection and make iterating possible.
  2. Collection: It is for storing objects as single entity.
  3. List: Collection in which insertion order is preserved.
  4. Set: Collection in which duplicates are not allowed.
  5. Queue: Queue is collection used store objects before processing. Simmilar to list but insertionis only possible at start and can be accessed from the end.
  6. Deque:It is double ended queue.
  7. SortedSet: Set in which elements are inserted in some order.
  8. NavigableSet: It allow to navigate through elements of Set.
  9. Iterator:This interface allow to iterate over the elements of collection. Maps are not iterable.
  10. ListIterator: List iterator allow bidirectional traversing.
  11. Map: Map allow us to store key, value pairs. Where duplicate keys are not allowed and each key maps only one value.
  12. SortedMap: Map in which we can specify sorting order of element.
  13. ConcurrentMap: Map allow concurrent access of elemnts by multiple threads.
  14. NavigableMap: Sorted map that facilitate navigataion from closest matching elements.
  15. ConcurrentNavigableMap: Concurrent and navigable map.

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Index

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.