INTRODUCTION OF COLLECTIONS

Introduction of Collections


Limitations of Arrays:

  • Array size is fixed. Once we initialize the Array size we can’t decreased/increased.

  • Array can hold one type of data. It can’t hold multiple type of data.

  • Manipulation of data is not efficient.

  • Customization is not possible.

  • In order to overcome Array limitations,Sun people came up with one new concept i.e. collections frame work .

COLLECTION FRAMEWORK:

    Collection framework is the standardized mechanism of grouping of similar or dissimilar type of objects into a single object. This single object is known as collection framework object. In collections generally we will use 3 words with similar type, they are

      collections it’s a concept or frame work name.
      Collections it’s a class.
      Collection it’s an Interface.

Goals of collection frameworks:

  • Collection framework improves the performance of JAVA, J2EE projects (when we want to transfer the bulk amount of data from client to server and server to client, using collection framework we can transfer that entire data at a time).

  • Collection framework allows us to prove similar or dissimilar type of objects

  • Collection framework contains adaptability feature (adaptability is the process of adding one collection object at the end of another collection object).

  • Collection framework is algorithmic oriented (collection framework contains various sorting and searching techniques of data structures as a predefined concepts).

  • In order to deal with collection framework we must import a package called java.util.*

  • By using collections we can do every activity similar to Arrays.

  • Collection framework is dynamic in nature i.e., they are extends (arrays contains the size which is fixed in nature and they allows similar type of data).
    i.e.we can able to change the length/size of the collections dynamically at runtime. For Example if we create any collection item with initial size is 10. Means we can able to add more than 10 elements to the collection.
    After adding more than 10 elements, the collection size will become double to the initial size. Means collection size is reinitialized to 20.

  • Collections can take multiple data type values.

  • Before jdk1.5 collections took only derived data type values. It won’t take any primitive values. But after introducing Auto Boxing and Un Boxing, collections framework supports even primitive data types also.

  • Collections which are part of jdk1.2 version are called as Legacy collections.

  • Initially there are only 6 concepts in collections i.e., “Vectors and Stack”, “Hash Table, Dictionary and Properties” and “Enumeration”. Those are called as Legacy collections or old collections or called native classes.

  • Note
      Collection framework is divided into two categories. They are new collection framework and legacy (old) collection frameworks

java.util.Collection:

    Collection is an interface whose object allows us to organize similar or different types of objects into single object. The Collection interface is having the following features:
  • It is available at the top of the hierarchy of all the interfaces which are available in the collection framework.

  • An object Collection allows us to add duplicate elements.

  • Collection of objects always displays the data in forward direction only.

  • Collection of objects will print the data on the console in random order.

  • Collection of objects always allows us to insert an element at end only i.e., we cannot insert an element at the specific position.

  • In Collection interface there are 3 sub interfaces as listed bellow

      1. List
      2. Set
      3. Queue

Structure of Collection:

Java Setup Wizard
Full Structure of Collection