Collection Framework

Limitations of Object Array:-

⇒ Arrays are fixed in size i.e once we created an array there is no chance of increasing or decreasing the size our requirement i.e if we don’t know the size in advance, arrays are not recommended to use.

⇒ Arrays can hold only homogeneous data elements.

Student [] s = new student [ 100 ] ;

s [ 0 ] = new Student () ;

s [ 1 ] = new Customer () ; // compile time error, incompatible type

found : customer

required : student

⇒ But we can resolve this problem by using Object Array

Object [] a = new student [ 100 ] ;

a [ 0 ] = new Student () ;

a [ 1 ] = new Customer () ;

a [ 1 ] = new Teacher () ;

⇒ There is no underlying data structure for array. Hence ready made method support is not available. For every requirement compulsory we have to write code.

To resolve above problems, sun people introduced collections concept.

  • Collections are Growable in nature i.e based on our requirement we can increase or decrease capacity.
  • For every collection class underlying data structure present hence for every requirement ready mode method support is available.
  • Collections an hold both homogeneous and Heterogeneous elements.
  • being a programmer, just we have to know how to use that functionality and we not responsible to define that functionality.
  • Difference b/n Arrays and Collections.
Arrays:-
  1. Arrays are fixed in size.
  2. Memory point of view, Arrays are not recommended to use.
  3. Performance point of view Arrays are recommended to used.
  4. Hold homogeneous elements.
  5. For every requirement no ready made methods are not available, because underlying data structure is not available.
  6. Arrays can hold both primitives & Objects.
Collections:-
  1. Growable in nature.
  2. Memory point of view, collections are recommended to use.
  3. Performance point of view Arrays are not recommended to used.
  4. Hold both homogeneous and Heterogeneous elements.
  5. Every collection class is implemented based on data structure & hence ready made method support is available for every requirement.
  6. Collections can hold both primitives & Objects.

 

Collection Framework

It define a group group of classes and interfaces which be used for representing a group of Objects as a single entity.

C + + (container) java (collection)
Standard template Library collection framework
  • Collection Framework define the following (9) nine key interfaces.

Collection ( I )

  • This can be used for representing group of individual Objects as a single entity.
  • This interface define several utility methods. Which can be apply on any collection Object.
  • In general, this interface acts as a root interface of collection Framework.

Collection vs Collections

Collection is an interface which can be used for representing group of Objects as single entity. But collections as an utility class to define several utility methods for collection implemented Objects.

 

The Author

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply