Collection Framework Flashcards
What is Collections Framework?
The Collections Framework is a sophisticated hierarchy of
interfaces and classes that provide state-of-art technology for
managing groups of objects.
Primary advantages of a collections
❑ Reduces programming effort
❑ Increases performance
❑ Provides interoperability between unrelated APIs
❑ Reduces the effort required to learn APIs
❑ Reduces the effort required to design and implement APIs
❑ Fosters software reuse
What is List Interface?
❑ Java.util.List is a child interface of Collection.
❑ List is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order it allows positional access and insertion of elements.
❑ List Interface is implemented by ArrayList, LinkedList, Vector and Stack classes.
Think of a school management application. You have
a list of students stored in the Database. To display those
names on the user interface, You have to make a call
to the database and store these elements and
populate those list elements on UI.
What is the best approach you are suggesting?
Answer – An Array?
String arr[]=new String[5]; arr[0]=“Anne”; arr[1]=“Peter”; arr[2]=“Shenan”; arr[3]=“Pete”; arr[4]=“Diana”;
Problems?
• Arrays are of fixed length. You can not change the size of
the arrays once they are created.
• You can not accommodate an extra element in an array
after they are created.
• Memory is allocated to an array during its creation
only, much before the actual elements are added to it.
Answer – ArrayList Class
9
❑ ArrayList class extends the AbstractList class and implements
the List interface.
❑ ArrayList support dynamic arrays (can increase and decrease
size dynamically).
❑ Elements can be inserted at or deleted from a particular
position
❑ ArrayList class has many methods to manipulate the stored
objects
❑ If generics are not used, ArrayList can hold any type of
objects.