3. 1. Intro
A collection is an object that represents a group of
objects (such as the classic Vector class). A
collections framework is a unified architecture for
representing and manipulating collections,
enabling collections to be manipulated
independently of implementation details.
4. Advantages of using
collection ?
Tip
In this question,
Think of real world
example
Try to think the
benefits of handling
things as a group.
5. Few advantages are
● Reduces programming effort by providing data structures and algorithms so
you don't have to write them yourself.
● Increases performance by providing high-performance implementations of data
structures and algorithms. Because the various implementations of each
interface are interchangeable, programs can be tuned by switching
implementations.
● Reduces the effort required to learn APIs by requiring you to learn multiple ad
hoc collection APIs.
● Reduces the effort required to design and implement APIs by not requiring
you to produce ad hoc collections APIs.
● Fosters software reuse by providing a standard interface for collections and
algorithms with which to manipulate them.
6. The collection framework
internally uses generics.
Let’s code to
understand the basics.
Tip
Open up a text editor
( gedit, Notepad )
and start typing hello
world program in
java
7. 2. Examples
Hit the url :
https://github.com/Pradhan10/Java-Collections-and-Generics
➔ The difference between storing data in array vs arraylist ?
Start with drawing analogies to array in C.
➔ How are we printing all elements in arraylist ?
Did we write the for loop to iterate all elements in list
anywhere ?
8. Meet Joshua Bloch
He wrote most of the java Collection
framework and was chief architect in
development of language.
9. Story for illustration purposes only
The main interfaces of the Java Collections Framework
10. Why do you think
the map interface
was implemented
seperately ?
Tip
Look at the
mathematical
difference between
a set, a sequence
and a mapping.
11. Code example two
Hit the url :
https://github.com/Pradhan10/Java-Collections-a
nd-Generics/blob/master/QueueClass.java
16. Cast-iron guarantee
The implicit casts added by
the compilation of generics
never fail. (applies only when no unchecked warnings have been issued
by the compiler.)
18. The 3 most used type parameters
1 : <E>, <T>, <K, V> (Used in Map interface)
2 : ? extends E (Used in iterator class)
3 : ? super T (Used in Comparator method)