SlideShare a Scribd company logo
1 of 16
Containers DhrubojyotiKayal
Collections a sequence of individual elements with one or more rules applied to them.  List, Queue, Set Map a group of key-value object pairs, allowing you to look up a value using a key.  Basics
Lists promise to maintain elements in a particular sequence. ArrayList - excels at randomly accessing elements, but is slower when inserting and removing elements in the middle of a List.  LinkedList - which provides optimal sequential access, with inexpensive insertions and deletions from the middle of the List.  List
List list = new ArrayList(); list.add(1); Integer val = (Integer) list.get(0); System.out.println(list.size()); list.add(2); list.remove(0); System.out.println(list.size()); List in Action
Declare an ArrayList and fill 100 integers in it. Now loop through the list to print the list. Exercise
List list = new ArrayList(); list.add(1); list.add("john"); Integer val2 = (Integer) list.get(1); Paving way for Generics
Allow only a specific type to be added in a list Runtime system takes care of the type casts under the hood. List<Integer> list = new ArrayList<Integer> list.add(1); list.add(“hi”); Generics
Declare an ArrayList and fill it with 100 integers Now iterate the list using for each loop Exercise
An iterator is an object whose job is to move through a sequence and select each object in that sequence without the client programmer knowing or caring about the underlying structure of that sequence. Java Iterator can move in only one direction Typical workflow Get iterator object - list.iterator() Get the next object in the sequence with next( ). See if there are any more objects in the sequence with hasNext( ).   Iterator
Repeat the previous example with an Iterator Excercise
Concrete implementation of Set interface Duplicate free collection Opmtized for rapid lookup Set set = new HashSet set.add(1); set.contains(1)  boolean HashSet
Declare an integer array with 6 elements with elements – {1,5,3,5,6,3} Now find the duplicates in that array. Excercise
Implements the basic List interface Insertion and removal in the middle of the List is more efficient than ArrayList It is less efficient for random-access operations. Adds methods that allow it to be used as a stack, a Queue or a double-ended queue (deque). add(Object o) addFirst(Object o)  addLast(Object o) removeFirst() removeLast() getFirst(); getLast(); LinkedList
Write a Java program to implement a Queue with a LinkedList Write a Java program to implement a Stack with a LinkedList Excercise
Implementation of Map Key Value pair Useful for cache and lookup Map<String, Integer> map = new HashMap<String, Integer> map.get(key) map.put(key,value); HashMap
Q&A

More Related Content

What's hot (20)

07 java collection
07 java collection07 java collection
07 java collection
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Java collection
Java collectionJava collection
Java collection
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Python - Lecture 4
Python - Lecture 4Python - Lecture 4
Python - Lecture 4
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Presentation1
Presentation1Presentation1
Presentation1
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Hash set (java platform se 8 )
Hash set (java platform se 8 )Hash set (java platform se 8 )
Hash set (java platform se 8 )
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
Python set
Python setPython set
Python set
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Java
JavaJava
Java
 
Groovy
GroovyGroovy
Groovy
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 

Similar to 16 containers

Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & setsRatnaJava
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )charan kumar
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work pptRanjith Alappadan
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructuresNguync91368
 
collection framework in java
collection framework in javacollection framework in java
collection framework in javaMANOJ KUMAR
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Aijaz Ali Abro
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections frameworkRavi Chythanya
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionssuseredfbe9
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.jstimourian
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google CollectionsAndré Faria Gomes
 

Similar to 16 containers (20)

Java collections
Java collectionsJava collections
Java collections
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
Lecture2
Lecture2Lecture2
Lecture2
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
 

More from dhrubo kayal

01 session tracking
01   session tracking01   session tracking
01 session trackingdhrubo kayal
 
03 handling requests
03 handling requests03 handling requests
03 handling requestsdhrubo kayal
 
02 up close with servlets
02 up close with servlets02 up close with servlets
02 up close with servletsdhrubo kayal
 
01 overview-servlets-and-environment-setup
01 overview-servlets-and-environment-setup01 overview-servlets-and-environment-setup
01 overview-servlets-and-environment-setupdhrubo kayal
 
14 initialization & cleanup
14   initialization & cleanup14   initialization & cleanup
14 initialization & cleanupdhrubo kayal
 
08 class and object
08   class and object08   class and object
08 class and objectdhrubo kayal
 
04 data types & variables
04   data types & variables04   data types & variables
04 data types & variablesdhrubo kayal
 
03 hello world with java
03   hello world with java03   hello world with java
03 hello world with javadhrubo kayal
 

More from dhrubo kayal (20)

Cipla 20-09-2010
Cipla   20-09-2010Cipla   20-09-2010
Cipla 20-09-2010
 
01 session tracking
01   session tracking01   session tracking
01 session tracking
 
03 handling requests
03 handling requests03 handling requests
03 handling requests
 
02 up close with servlets
02 up close with servlets02 up close with servlets
02 up close with servlets
 
01 overview-servlets-and-environment-setup
01 overview-servlets-and-environment-setup01 overview-servlets-and-environment-setup
01 overview-servlets-and-environment-setup
 
19 reflection
19   reflection19   reflection
19 reflection
 
18 concurrency
18   concurrency18   concurrency
18 concurrency
 
17 exceptions
17   exceptions17   exceptions
17 exceptions
 
15 interfaces
15   interfaces15   interfaces
15 interfaces
 
14 initialization & cleanup
14   initialization & cleanup14   initialization & cleanup
14 initialization & cleanup
 
13 inheritance
13   inheritance13   inheritance
13 inheritance
 
12 encapsulation
12   encapsulation12   encapsulation
12 encapsulation
 
11 static
11   static11   static
11 static
 
10 access control
10   access control10   access control
10 access control
 
09 packages
09   packages09   packages
09 packages
 
08 class and object
08   class and object08   class and object
08 class and object
 
07 flow control
07   flow control07   flow control
07 flow control
 
05 operators
05   operators05   operators
05 operators
 
04 data types & variables
04   data types & variables04   data types & variables
04 data types & variables
 
03 hello world with java
03   hello world with java03   hello world with java
03 hello world with java
 

16 containers

  • 2. Collections a sequence of individual elements with one or more rules applied to them. List, Queue, Set Map a group of key-value object pairs, allowing you to look up a value using a key. Basics
  • 3. Lists promise to maintain elements in a particular sequence. ArrayList - excels at randomly accessing elements, but is slower when inserting and removing elements in the middle of a List. LinkedList - which provides optimal sequential access, with inexpensive insertions and deletions from the middle of the List. List
  • 4. List list = new ArrayList(); list.add(1); Integer val = (Integer) list.get(0); System.out.println(list.size()); list.add(2); list.remove(0); System.out.println(list.size()); List in Action
  • 5. Declare an ArrayList and fill 100 integers in it. Now loop through the list to print the list. Exercise
  • 6. List list = new ArrayList(); list.add(1); list.add("john"); Integer val2 = (Integer) list.get(1); Paving way for Generics
  • 7. Allow only a specific type to be added in a list Runtime system takes care of the type casts under the hood. List<Integer> list = new ArrayList<Integer> list.add(1); list.add(“hi”); Generics
  • 8. Declare an ArrayList and fill it with 100 integers Now iterate the list using for each loop Exercise
  • 9. An iterator is an object whose job is to move through a sequence and select each object in that sequence without the client programmer knowing or caring about the underlying structure of that sequence. Java Iterator can move in only one direction Typical workflow Get iterator object - list.iterator() Get the next object in the sequence with next( ). See if there are any more objects in the sequence with hasNext( ). Iterator
  • 10. Repeat the previous example with an Iterator Excercise
  • 11. Concrete implementation of Set interface Duplicate free collection Opmtized for rapid lookup Set set = new HashSet set.add(1); set.contains(1)  boolean HashSet
  • 12. Declare an integer array with 6 elements with elements – {1,5,3,5,6,3} Now find the duplicates in that array. Excercise
  • 13. Implements the basic List interface Insertion and removal in the middle of the List is more efficient than ArrayList It is less efficient for random-access operations. Adds methods that allow it to be used as a stack, a Queue or a double-ended queue (deque). add(Object o) addFirst(Object o) addLast(Object o) removeFirst() removeLast() getFirst(); getLast(); LinkedList
  • 14. Write a Java program to implement a Queue with a LinkedList Write a Java program to implement a Stack with a LinkedList Excercise
  • 15. Implementation of Map Key Value pair Useful for cache and lookup Map<String, Integer> map = new HashMap<String, Integer> map.get(key) map.put(key,value); HashMap
  • 16. Q&A