Android Term Collection: Why we have to use Collection?

Definitaion:  The Java collections framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures


Assign variable

span style="font-weight: 400;">We can assign the each value of object by using identifiers.

For example ,we have list of student name which contains 5 names.

Then we can assign them by using different identifiers.

String studentName1 = “Bhavik”;

String studentName1 = “Dhaval”;

String studentName1 = “Hardik”;

String studentName1 = “Kunal”;

String studentName1 = “Tushar”;

It is quit good for above list but when size is increased it become very difficult to handle it.if above list have 1000 student name then this tequnique is very dangerous. So  It not able to handle such a situation where size is increased.

So array is good option in such a situation, to Repeat where we have to handle group of object in large number of size


t: 400;"> In computer programming languages, an array is a group of objects with the same data type (Homogeneous) that can be addressed individually and we can apply various algorithms on array like sorting and searching by our own way.

If you are developer and you are going to open all nuts and bolts of collection framework than I am sure that  you are most familiar about Array including creation and handling various flaky operation on array.

Let me repeat all the thing about array very quicly;

dataType[] arrayReference  = new dataType[size];

where Size(int) is number of elements which will going to include in array.

Where dataType is same for all the elements (Homogeneous Datatype) which comes under array called arrayReference in above syntax.

So if we take a datatype as string the expel should be look like,

String[] names = new String[3];

names[0] = “joe”;

names[0] = “jane”;

names[0] = “Herkimer”;

So you can imagine the internal structure like this.

You might be getting confused with word call heterogeneous in  above stuffs. Don’t worry  it is so simple .

Homogeneous  Mixture:

Homogeneous  Mixture:full" src="" alt="" width="368" height="252" srcset=" 368w, 300w, 135w" sizes="(max-width: 368px) 100vw, 368px" />

Homogeneous => if All elements should  have same data type than it is call Homogenous.In above example names (Remember?? It was Array reference ) have all the elements which has same data type of String.

Heterogeneous =>  if elements  may have different data type than it is call Homogenous.For example, names[0] = “hello”;

Names[1] = 2;

Names[2] = object;

So elements may have different data type. Its is called heterogeneous. Unfortunately  array does not support heterogeneous datatype.  It does only support homogeneous datatype. but don’t worry, collection is there for us who take care our lines of code and  precious time too. We will see it.

So up to you, you might be getting smell of limitation of array as I have gave little hint about limitation of it. Don’t be confused look at below list of all limitations.

Limitation of Array :

  • Limitation of Array :pan style="font-weight: 400;"> So if data came dynamically suppose it came from network then we can fix the elements in terms of size. At that point time array is not perfect option  for us what   we are looking for. So Array does not support  group of object which have dynamic size.
  • Array support only homogeneous  datatype. So if our elements may have different datatype in some cases then array is  not suitable option for us.
  • Array does not provide inbuilt data handling techniques. if we have to apply various sorting or searching technique or other data related technique like:
  1. we don’t want to allow duplicate value  in array.
  2. If I have to check whether given object is exist in array or not.
  3. Do  Have to replace object with other.
  4. If we want to arrange all elements  of array in particular sorting fashion.
  5. Do I want to work on key value pair.

If we may face in any of  above situation in our project than we have to write bunch of code for each requirements. So array does not take care of our time in order to perform similar situations which are mention over above list.

So due to over come all above limitation , collection is perfect option for us to handle limitation with just few line of code.

So, Basically collection is java framework which have different sets of classes and interface which is contributing lead role in order to do all the major techniques associated with data types. Hierarchy of  classes and interfaces given below.

You might afraid by seeing above structure.  Don’t worry about it. We will explore all the things about each components of it in part of our Collection series.

stay tune and get ready for next session about overview of Collection in next blog.