SlideShare a Scribd company logo
1 of 22
Collection is a java object that is used to store
homogeneous & hetrogeneous , Duplicate & unique
objects with out size limitation for carrying multiple
objects At a time from one application to another
application among multiple layers of MVC
architecture as method arguments and return type
Problem with Object[] to collect objects:
1.It allows us to store only same type of elements
2.It is fixed in size
3.Doesnot inbuilt methods for performing different
operations
All collection classes are defined in java.util package
Sun developed many collection classes among them 13 are important , they
are
ArrayList HashSet HashMap
Vector LinkedHashSet LinkedHashMap
Stack TreeSet TreeMap
LinkedList Hashtable
PriorityQueue Properties
Some helper/utility classes
Collections Scanner Locale Date
Arrays StringTockenizer ResourceBundle Calender
Random Currently GregoroanCale
der
We can collect objects in 2 ways
1.In array format- in this format object does not have identity
2.In (key , value) pair format- in this format object has identit
In java 1.0 version SUN only introduced 2 classes to collect
objects in above formats
a. Vector :It stores objects in array format
b. Hashtable: It stores objects in (key, value ) pair format
In java 1.2 version all collections are collectively called as
Collection framework
1.Collection hierarchy
2.Map hierarchy
*
Collection hierarchy classes are divided into 3 categories-
Set,List, and Queue
Collection hierarchy classes we can collect unique and duplicate
objects in array format
Set is a unique collection , it does not allow duplicate elements
Set is the super interface for all unique collection class
List is duplicate collection, it allows duplicate elements
List is the super interface for all duplicate collection class
*
Set is an unsorted and unordered, means it stores elements
without index
SortedSet: is a sub interface of set that stores elements in
sorted order either in Ascending or descending order based on
the object’s natural sorting order
NavigableSet: is a sub interface of sortedSet .It is added in java
6 to add more navigation method to sorted set
*
In a List implimented classes Vector , ArrayList and LinkedList
are the class
ArrayList,Vector:It stores objects in array format
We choose these two classes to store elements in indexed order
and to retrieveThem radomly
Specific Functionalities of these two class:
1.Duplicate objects are not allowed in indexed order
2.Heterogeneous objects are allowed
3.Insertion order is preserved
4.Implemented data strcture is growable array
5.Null insertion is possible, more than one null is allowed
6.Initial capacity is 10 , incrementel capacity is double
Difference between Array list and Vector
Vector object is thread-safe: It means synchronized object-so
multiple threads Cannot modify this object concurrently.
ArrayList object is non threadsafe: it means it is not
synchronized object.
It is best suitable in multithread model application
Limitation of both classes:
Inserting and removing elements in middle is costlier operation
LinkkedList:
We must use linked list only when we have more operations
or inserting and
removing at beining or in the middle of collection
Linked list is not suitable for adding operations because it
consumes more memory gives less performance
It is not synchrinized object
It is a ordered collection , indexed order
It uses equals method in searching and removing elements
from collections
*
Queue is a root icomparator, or interface of all types
of queues
1.Priority Queues: which order elements according to
a supplied comparator, or the elements natural
ordering
2.LIFO queues : which ordered the elements LIFO
3.FIFOqueue: all new elements are inserted at the tail
of the queue
*
a stack is a group of objects that allows to restore
elements in last in first out manner
Stack is a legacy collection it is a subclass of vector
When we add objects to stack those objects are internally
added to vector in insertion order
Public E push(E item)
Public E pop()
Public E peck()
Public boolean empty()
Public int search (Object o)
*
In a map , key should be unique and values can be duplicated
Each (key , value) is called an entry . In map by default entries
are not sorted
SortedMap: is the sub interface of map
It sorts entries based on key natural sorting order
*
HashMap holds the data in the form of key-value pairs where
each key is associated with one value.
2) HashMap doesn’t allow duplicate keys. But it can have
duplicate values.
3) HashMap can have multiple null values and only one null key.
4) HashMap is not synchronized. To get the synchronized
HashMap, use Collections.synchronizedMap() method.
5) HashMap maintains no order.
6) HashMap gives constant time performance for the operations
like get() and put() methods.
7) Default initial capacity of HashMap is 16.
*
1) public V put(K key, V value)
This method inserts specified key-value mapping in the map. If map already has a
mapping for the specified key, then it rewrites that value with new value.
2) public void putAll(Map m)
This method copies all of the mappings of the map m to this map.
3) public V get(Object key)
This method returns the value associated with a specified key.
4) public int size()
This method returns the number of key-value pairs in this map.
5) public boolean isEmpty()
This method checks whether this map is empty or not.
6) public boolean containsKey(Object key)
This method checks whether this map contains the mapping for the specified
key.
7) public boolean containsValue(Object value)
This method checks whether this map has one or more keys mapping to the
specified value.
8) public V remove(Object key)
This method removes the mapping for the specified key.
9) public void clear()
This method removes all the mappings from this map.
10) public Set<K> keySet()
This method returns the Set view of the keys in the map.
11) public Collection<V> values()
This method returns Collection view of the values in the map.
12) public Set<Map.Entry<K, V>> entrySet()
This method returns the Set view of all the mappings in this map.
13) public V putIfAbsent(K key, V value)
This method maps the given value with specified key if this key is currently not
associated with a value or mapped to a null.
13) public boolean remove(Object key, Object value)
This method removes the entry for the specified key if this key is currently
mapped to a specified value.
14) public boolean replace(K key, V oldValue, V newValue)
This method replaces the oldValue of the specified key with newValue if the key is
currently mapped to oldValue.
15) public V replace(K key, V value)
This method replaces the current value of the specified key with new value.
*
1.For storing objects in arrray format,we must choose
collection hierarchy classes
2.For storing objects in (key,value) pair format, we choose
map hierarchy classes
3.For storing only unique elements, we must choose set
implemented classes
4.For storing hetrogeneous unique elements without worring
storing order, we must Choose HashSet
5.For storing heterogeneous unique elements in insertion order
We must choose LinkedHashSet
6.For storing only unique elements in sorting order we must
Choose TreeSet
7.For storing unique and/or duplicate elements in indexed
order, we must choose List implemented classes
8.For storing and retrieve duplicate elements in random access
we must choose List Implemented classes
9.For storing and retrieving elements in LIFO order we should
choose Stack
10.For storing unique entries , we must choose HashMap
11.For storing unique entries in sorting order , we must choose
Treemap
12.Hatable and HashMap both works similar, the only
difference is Hashtable is Threadsisafe
13.Properties class is used to store properties permanently
in file
public boolean isEmpty()
Public boolean add(Object o)
Public boolean addAll(Collection c)
Public boolean remove(Object obj)
Public boolean removeAll(Collection )
Public vlid clear()
Public boolean contains(Object o)
Public boolean containsAll(Object o)
Public boolean retains(Object o)
Public int size()
Public int hashCode()
Public Object[] toArray()
Public Object[] toArray(Object[] obj)
Public boolean equals(Object obj)
22.collections(1)

More Related Content

What's hot

Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - JavaDrishti Bhalla
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Edureka!
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Frameworkguestd8c458
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
 
collection framework in java
collection framework in javacollection framework in java
collection framework in javaMANOJ KUMAR
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
Collections
CollectionsCollections
CollectionsLinh Lê
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanZeeshan Khan
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections frameworkRavi Chythanya
 

What's hot (20)

Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
07 java collection
07 java collection07 java collection
07 java collection
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Java util
Java utilJava util
Java util
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Collections
CollectionsCollections
Collections
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
Generics
GenericsGenerics
Generics
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 

Similar to 22.collections(1)

Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40bhawna sharma
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructuresNguync91368
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionssuseredfbe9
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)SURBHI SAROHA
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxhemanth248901
 
computer notes - Stack
computer notes - Stackcomputer notes - Stack
computer notes - Stackecomputernotes
 
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
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfalicesilverblr
 

Similar to 22.collections(1) (20)

Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Java collections
Java collectionsJava collections
Java collections
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
computer notes - Stack
computer notes - Stackcomputer notes - Stack
computer notes - Stack
 
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)
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 

Recently uploaded

The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdfThe Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdfbelieveminhh
 
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON ESCORTS SERVICE PROVIDE
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON  ESCORTS SERVICE PROVIDEGURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON  ESCORTS SERVICE PROVIDE
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON ESCORTS SERVICE PROVIDEkajalroy875762
 
Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...
Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...
Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...pr788182
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 MonthsIndeedSEO
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...ssuserf63bd7
 
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...ssuserf63bd7
 
Moradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in PenacovaMoradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in Penacovaimostorept
 
Asansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Available
Asansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service AvailableAsansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Available
Asansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Availablepr788182
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptxRoofing Contractor
 
A DAY IN THE LIFE OF A SALESPERSON .pptx
A DAY IN THE LIFE OF A SALESPERSON .pptxA DAY IN THE LIFE OF A SALESPERSON .pptx
A DAY IN THE LIFE OF A SALESPERSON .pptxseemajojo02
 
Ital Liptz - all about Itai Liptz. news.
Ital Liptz - all about Itai Liptz. news.Ital Liptz - all about Itai Liptz. news.
Ital Liptz - all about Itai Liptz. news.htj82vpw
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxCynthia Clay
 
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDEJIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDEkajalroy875762
 
Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...pr788182
 
Goa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service Available
Goa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service AvailableGoa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service Available
Goa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service AvailableCall Girls Mumbai
 

Recently uploaded (20)

WheelTug Short Pitch Deck 2024 | Byond Insights
WheelTug Short Pitch Deck 2024 | Byond InsightsWheelTug Short Pitch Deck 2024 | Byond Insights
WheelTug Short Pitch Deck 2024 | Byond Insights
 
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdfThe Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
 
Home Furnishings Ecommerce Platform Short Pitch 2024
Home Furnishings Ecommerce Platform Short Pitch 2024Home Furnishings Ecommerce Platform Short Pitch 2024
Home Furnishings Ecommerce Platform Short Pitch 2024
 
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON ESCORTS SERVICE PROVIDE
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON  ESCORTS SERVICE PROVIDEGURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON  ESCORTS SERVICE PROVIDE
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON ESCORTS SERVICE PROVIDE
 
Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...
Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...
Pimpri Chinchwad Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Servi...
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Buy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail AccountsBuy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail Accounts
 
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
 
Moradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in PenacovaMoradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in Penacova
 
Asansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Available
Asansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service AvailableAsansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Available
Asansol Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Available
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
A DAY IN THE LIFE OF A SALESPERSON .pptx
A DAY IN THE LIFE OF A SALESPERSON .pptxA DAY IN THE LIFE OF A SALESPERSON .pptx
A DAY IN THE LIFE OF A SALESPERSON .pptx
 
Ital Liptz - all about Itai Liptz. news.
Ital Liptz - all about Itai Liptz. news.Ital Liptz - all about Itai Liptz. news.
Ital Liptz - all about Itai Liptz. news.
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptx
 
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDEJIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
 
Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Berhampur Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Goa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service Available
Goa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service AvailableGoa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service Available
Goa Call Girls Just Call 👉📞9731111159 Top Class Call Girl Service Available
 

22.collections(1)

  • 1.
  • 2. Collection is a java object that is used to store homogeneous & hetrogeneous , Duplicate & unique objects with out size limitation for carrying multiple objects At a time from one application to another application among multiple layers of MVC architecture as method arguments and return type Problem with Object[] to collect objects: 1.It allows us to store only same type of elements 2.It is fixed in size 3.Doesnot inbuilt methods for performing different operations
  • 3. All collection classes are defined in java.util package Sun developed many collection classes among them 13 are important , they are ArrayList HashSet HashMap Vector LinkedHashSet LinkedHashMap Stack TreeSet TreeMap LinkedList Hashtable PriorityQueue Properties Some helper/utility classes Collections Scanner Locale Date Arrays StringTockenizer ResourceBundle Calender Random Currently GregoroanCale der
  • 4. We can collect objects in 2 ways 1.In array format- in this format object does not have identity 2.In (key , value) pair format- in this format object has identit In java 1.0 version SUN only introduced 2 classes to collect objects in above formats a. Vector :It stores objects in array format b. Hashtable: It stores objects in (key, value ) pair format In java 1.2 version all collections are collectively called as Collection framework 1.Collection hierarchy 2.Map hierarchy
  • 5.
  • 6. * Collection hierarchy classes are divided into 3 categories- Set,List, and Queue Collection hierarchy classes we can collect unique and duplicate objects in array format Set is a unique collection , it does not allow duplicate elements Set is the super interface for all unique collection class List is duplicate collection, it allows duplicate elements List is the super interface for all duplicate collection class
  • 7. * Set is an unsorted and unordered, means it stores elements without index SortedSet: is a sub interface of set that stores elements in sorted order either in Ascending or descending order based on the object’s natural sorting order NavigableSet: is a sub interface of sortedSet .It is added in java 6 to add more navigation method to sorted set
  • 8. * In a List implimented classes Vector , ArrayList and LinkedList are the class ArrayList,Vector:It stores objects in array format We choose these two classes to store elements in indexed order and to retrieveThem radomly Specific Functionalities of these two class: 1.Duplicate objects are not allowed in indexed order 2.Heterogeneous objects are allowed 3.Insertion order is preserved 4.Implemented data strcture is growable array 5.Null insertion is possible, more than one null is allowed 6.Initial capacity is 10 , incrementel capacity is double
  • 9. Difference between Array list and Vector Vector object is thread-safe: It means synchronized object-so multiple threads Cannot modify this object concurrently. ArrayList object is non threadsafe: it means it is not synchronized object. It is best suitable in multithread model application Limitation of both classes: Inserting and removing elements in middle is costlier operation
  • 10. LinkkedList: We must use linked list only when we have more operations or inserting and removing at beining or in the middle of collection Linked list is not suitable for adding operations because it consumes more memory gives less performance It is not synchrinized object It is a ordered collection , indexed order It uses equals method in searching and removing elements from collections
  • 11. * Queue is a root icomparator, or interface of all types of queues 1.Priority Queues: which order elements according to a supplied comparator, or the elements natural ordering 2.LIFO queues : which ordered the elements LIFO 3.FIFOqueue: all new elements are inserted at the tail of the queue
  • 12. * a stack is a group of objects that allows to restore elements in last in first out manner Stack is a legacy collection it is a subclass of vector When we add objects to stack those objects are internally added to vector in insertion order Public E push(E item) Public E pop() Public E peck() Public boolean empty() Public int search (Object o)
  • 13. * In a map , key should be unique and values can be duplicated Each (key , value) is called an entry . In map by default entries are not sorted SortedMap: is the sub interface of map It sorts entries based on key natural sorting order
  • 14. * HashMap holds the data in the form of key-value pairs where each key is associated with one value. 2) HashMap doesn’t allow duplicate keys. But it can have duplicate values. 3) HashMap can have multiple null values and only one null key. 4) HashMap is not synchronized. To get the synchronized HashMap, use Collections.synchronizedMap() method. 5) HashMap maintains no order. 6) HashMap gives constant time performance for the operations like get() and put() methods. 7) Default initial capacity of HashMap is 16.
  • 15. * 1) public V put(K key, V value) This method inserts specified key-value mapping in the map. If map already has a mapping for the specified key, then it rewrites that value with new value. 2) public void putAll(Map m) This method copies all of the mappings of the map m to this map. 3) public V get(Object key) This method returns the value associated with a specified key. 4) public int size() This method returns the number of key-value pairs in this map. 5) public boolean isEmpty() This method checks whether this map is empty or not.
  • 16. 6) public boolean containsKey(Object key) This method checks whether this map contains the mapping for the specified key. 7) public boolean containsValue(Object value) This method checks whether this map has one or more keys mapping to the specified value. 8) public V remove(Object key) This method removes the mapping for the specified key. 9) public void clear() This method removes all the mappings from this map. 10) public Set<K> keySet() This method returns the Set view of the keys in the map. 11) public Collection<V> values() This method returns Collection view of the values in the map.
  • 17. 12) public Set<Map.Entry<K, V>> entrySet() This method returns the Set view of all the mappings in this map. 13) public V putIfAbsent(K key, V value) This method maps the given value with specified key if this key is currently not associated with a value or mapped to a null. 13) public boolean remove(Object key, Object value) This method removes the entry for the specified key if this key is currently mapped to a specified value. 14) public boolean replace(K key, V oldValue, V newValue) This method replaces the oldValue of the specified key with newValue if the key is currently mapped to oldValue. 15) public V replace(K key, V value) This method replaces the current value of the specified key with new value.
  • 18.
  • 19. * 1.For storing objects in arrray format,we must choose collection hierarchy classes 2.For storing objects in (key,value) pair format, we choose map hierarchy classes 3.For storing only unique elements, we must choose set implemented classes 4.For storing hetrogeneous unique elements without worring storing order, we must Choose HashSet 5.For storing heterogeneous unique elements in insertion order We must choose LinkedHashSet 6.For storing only unique elements in sorting order we must Choose TreeSet
  • 20. 7.For storing unique and/or duplicate elements in indexed order, we must choose List implemented classes 8.For storing and retrieve duplicate elements in random access we must choose List Implemented classes 9.For storing and retrieving elements in LIFO order we should choose Stack 10.For storing unique entries , we must choose HashMap 11.For storing unique entries in sorting order , we must choose Treemap 12.Hatable and HashMap both works similar, the only difference is Hashtable is Threadsisafe 13.Properties class is used to store properties permanently in file
  • 21. public boolean isEmpty() Public boolean add(Object o) Public boolean addAll(Collection c) Public boolean remove(Object obj) Public boolean removeAll(Collection ) Public vlid clear() Public boolean contains(Object o) Public boolean containsAll(Object o) Public boolean retains(Object o) Public int size() Public int hashCode() Public Object[] toArray() Public Object[] toArray(Object[] obj) Public boolean equals(Object obj)