SlideShare a Scribd company logo
1 of 28
Download to read offline
Collections and Generics
Collection framework Overview
• The collection is an object that represents a group of objects.
• A collections framework is a unified architecture for representing and
manipulating collections, allowing them to be manipulated
independently.
Cont’d
The collection framework consists
of
• Collection interfaces
• General purpose implementations
• Legacy implementations
• Special purpose implementations
• Concurrent implementations
• Wrapper implementations
• Convenience implementations
• Abstract implementations
• Algorithms
• Infrastructure
• Array utilities
Advantages of collection framework
• 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
Collection interfaces
• The collection interface is the primary which is implemented by all
the collection classes.
• There are totally 9 collection interfaces.
• Some of them are
• List interface
• Set interface
• Sortedset interface
Collection classes
Class Description
AbstractCollection Implements most of the collections interface
AbstractList Extends AbstractCollection and implements most of
the List interface
AbstractSequentialList Extends AbstractList for use by a collection that uses
sequential rather than random access of its elements
LinkedList Implements a linked list by extending
AbstractSequentialList
ArrayList Implements a dynamic array by extending AbstractList
AbstractSet Extends AnstractCollection and Implements most of
the Set interfaces
HashSet Extends AbstractSet for use with a hash table
TreeSet Implements a set stored in a tree. Extends AbstractSet
ArrayList
• The ArrayList class extends AbstractList and implements the List
interface.
• The constructors provided by the ArrayList class is
• ArrayList() – empty constructor
• ArrayList(Collection c) - initialized with the elements of the collection c
• ArrayList(int capacity) – specifying the initial capacity
• ArrayList<String> stringList = new ArrayList<String>();
ArrayList example
LinkedList
• LinkedList class implements the List interface.
• The LinkedList class provides uniformly named methods to get,
remove and insert an element at the beginning and end of the list.
• LinkedList also can be used as stack, queue, double ended queue
using these operations.
• The LinkedList() and LinkedList(collection c) are the constructors used
in this class.
• LinkedList<type> obj = new LinkedList<type>();
Methods used in LinkedList
Method Description
Void addFirst(Object ob) To add elements to the start of the list
Void addLast(Object ob) To add elements to the end of the list
Object getFirst() To obtain the first element
Object getLast() To obtain the last element
Object removeFirst() To remove the first element in the list
Object removeLast() To remove the last element in the list
LinkedList Example
HashSet Class
• This class implements the set interface, backed by a hash table.
• It provides constant time performance for operations
like add, remove, contains and size
HashSet example
TreeSet Class
• The TreeSet class implements the set interface, backed by a TreeMap
instance.
• TreeSet is an excellent choice when storing large amounts of sorted
information that must be found quickly.
TreeSet example
Iterator and ListIterator interface
• The iterator enables you to cycle through a collection obtaining or
removing elements.
• The ListIterator extends Iterator to allow multidirectional traversal of
a list and the modification of the element.
Methods of iterator interface
Method Description
Boolean hasNext() Returns true if the iteration has more elements
Object next() Returns the next element in the iteration
Void remove() Removes the underlying collection the last element
returned by the iterator
Methods of ListIterator interface
Method Description
Void add(Object e) Inserts the specified element into the list
Boolean hasNext() Returns true if this list iterator has more elements
when traversing the list in the forward direction
Boolean hasPrevious() Returns true if this list iterator has more elements
when traversing the list in the reverse direction
Object next() Returns the next element in the list
Int nextIndex() Returns the index of the element that would be
returned by a subsequent call to next
Object previous() Returns the previous element in the list
Int previousIndex() Returns the index of the element that would e
returned by a subsequent call to previous
Void remove() Removes from the list the last element that was
returned by next or previous
Void set(Object o) Replaces the last element returned by next or
previous with the specified element
Iterator and ListIterator example
User Defined Classes in Collection
Random Access Interface
• The RandomAccess interface identifies List implementations which
are faster to iterate using the List.get() method rather than using the
Iterator.next() method.
Working with maps
• Map interface:
• Map interface is used to map keys to value.
• A map cannot contain duplicate keys, each key can map to at most one value.
• A key is an object that is used to retrieve a value later.
• Given a key and a value, one can store the value in a map object.
• The value can be retrieved using the key.
• The get() and put() are two basic operations in map interface
• The put() is used to put a value into the map
• The get() is used to obtain a value passing the key as an argument
Methods provided by map interface
Method Description
Void clear() Removes all mappings from this map
Boolean containsKey(Object key) Returns true if the map contains a mapping for the
specified key
Boolean containsValue(Object key) Returns true if this map maps one or more keys to the
specified value.
Set entrySet() Returns a set view of the mappings contained in this
map
Boolean equals(Object o) Compares the specified object with this map for
equality
Object get(Object key) Returns the value to which this map mpas the
specified key
Cont’d
Method Description
Int hashCode() Returns the hash code value for this map
Boolean isEmpty() Returns true if this map contains no key-value
mappings
Set keyset() Returns a set view of the keys contained in this map
Object put(Object key, Object value) Associates the specified value with the specified key in
this map
Void putAll(Map t) Copies all of the mappings from the specified map to
this map
Object remove(Object key) Removes the mappings for this key from this map if it
is present
Int size() Returns number of key-value mappings in this map
Collection values() Returns a collection view of the values contained in
the map
HashMap class
• HashMap class is used for hash table based implementation of the
map interface.
• This implementation provides all the optional map operations and
permits null values and the null key.
• The HashMap class has two parameters
• Capacity – the capacity is the number of buckets in the hash table
• Load factor – is the measure of how full the hash table is allowed to get
before its capacity is automatically increased
Example for HashMap class
Any queries?
Thank you

More Related Content

What's hot

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37myrajendra
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packagesVINOTH R
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)Manisha Keim
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++HalaiHansaika
 
servlet in java
servlet in javaservlet in java
servlet in javasowfi
 

What's hot (20)

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Java Streams
Java StreamsJava Streams
Java Streams
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Generics
GenericsGenerics
Generics
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
exception handling
exception handlingexception handling
exception handling
 
07 java collection
07 java collection07 java collection
07 java collection
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++
 
servlet in java
servlet in javaservlet in java
servlet in java
 

Viewers also liked

Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakensRichardWarburton
 
Java Collections API
Java Collections APIJava Collections API
Java Collections APIAlex Miller
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
 

Viewers also liked (6)

Generics collections
Generics collectionsGenerics collections
Generics collections
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakens
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 

Similar to Collections and generics

Similar to Collections and generics (20)

oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Collections
CollectionsCollections
Collections
 
collections
collectionscollections
collections
 
Collections
CollectionsCollections
Collections
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Java collection
Java collectionJava collection
Java collection
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
Best core & advanced java classes in mumbai
Best core & advanced java classes in mumbaiBest core & advanced java classes in mumbai
Best core & advanced java classes in mumbai
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Java.util
Java.utilJava.util
Java.util
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
List in java
List in javaList in java
List in java
 

More from Muthukumaran Subramanian (20)

Struts introduction
Struts introductionStruts introduction
Struts introduction
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Overriding methods
Overriding methodsOverriding methods
Overriding methods
 
Oops (inheritance&interface)
Oops (inheritance&interface)Oops (inheritance&interface)
Oops (inheritance&interface)
 
Non access modifiers
Non access modifiersNon access modifiers
Non access modifiers
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Garbage collection in java
Garbage collection in javaGarbage collection in java
Garbage collection in java
 
Files in java
Files in javaFiles in java
Files in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Date class
Date classDate class
Date class
 
Currency class
Currency classCurrency class
Currency class
 
Timer class in java
Timer class in javaTimer class in java
Timer class in java
 
Calendar class in java
Calendar class in javaCalendar class in java
Calendar class in java
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Java introduction
Java introductionJava introduction
Java introduction
 

Recently uploaded

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Collections and generics

  • 2. Collection framework Overview • The collection is an object that represents a group of objects. • A collections framework is a unified architecture for representing and manipulating collections, allowing them to be manipulated independently.
  • 3. Cont’d The collection framework consists of • Collection interfaces • General purpose implementations • Legacy implementations • Special purpose implementations • Concurrent implementations • Wrapper implementations • Convenience implementations • Abstract implementations • Algorithms • Infrastructure • Array utilities
  • 4. Advantages of collection framework • 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
  • 5. Collection interfaces • The collection interface is the primary which is implemented by all the collection classes. • There are totally 9 collection interfaces. • Some of them are • List interface • Set interface • Sortedset interface
  • 6. Collection classes Class Description AbstractCollection Implements most of the collections interface AbstractList Extends AbstractCollection and implements most of the List interface AbstractSequentialList Extends AbstractList for use by a collection that uses sequential rather than random access of its elements LinkedList Implements a linked list by extending AbstractSequentialList ArrayList Implements a dynamic array by extending AbstractList AbstractSet Extends AnstractCollection and Implements most of the Set interfaces HashSet Extends AbstractSet for use with a hash table TreeSet Implements a set stored in a tree. Extends AbstractSet
  • 7. ArrayList • The ArrayList class extends AbstractList and implements the List interface. • The constructors provided by the ArrayList class is • ArrayList() – empty constructor • ArrayList(Collection c) - initialized with the elements of the collection c • ArrayList(int capacity) – specifying the initial capacity • ArrayList<String> stringList = new ArrayList<String>();
  • 9. LinkedList • LinkedList class implements the List interface. • The LinkedList class provides uniformly named methods to get, remove and insert an element at the beginning and end of the list. • LinkedList also can be used as stack, queue, double ended queue using these operations. • The LinkedList() and LinkedList(collection c) are the constructors used in this class. • LinkedList<type> obj = new LinkedList<type>();
  • 10. Methods used in LinkedList Method Description Void addFirst(Object ob) To add elements to the start of the list Void addLast(Object ob) To add elements to the end of the list Object getFirst() To obtain the first element Object getLast() To obtain the last element Object removeFirst() To remove the first element in the list Object removeLast() To remove the last element in the list
  • 12. HashSet Class • This class implements the set interface, backed by a hash table. • It provides constant time performance for operations like add, remove, contains and size
  • 14. TreeSet Class • The TreeSet class implements the set interface, backed by a TreeMap instance. • TreeSet is an excellent choice when storing large amounts of sorted information that must be found quickly.
  • 16. Iterator and ListIterator interface • The iterator enables you to cycle through a collection obtaining or removing elements. • The ListIterator extends Iterator to allow multidirectional traversal of a list and the modification of the element.
  • 17. Methods of iterator interface Method Description Boolean hasNext() Returns true if the iteration has more elements Object next() Returns the next element in the iteration Void remove() Removes the underlying collection the last element returned by the iterator
  • 18. Methods of ListIterator interface Method Description Void add(Object e) Inserts the specified element into the list Boolean hasNext() Returns true if this list iterator has more elements when traversing the list in the forward direction Boolean hasPrevious() Returns true if this list iterator has more elements when traversing the list in the reverse direction Object next() Returns the next element in the list Int nextIndex() Returns the index of the element that would be returned by a subsequent call to next Object previous() Returns the previous element in the list Int previousIndex() Returns the index of the element that would e returned by a subsequent call to previous Void remove() Removes from the list the last element that was returned by next or previous Void set(Object o) Replaces the last element returned by next or previous with the specified element
  • 20. User Defined Classes in Collection
  • 21. Random Access Interface • The RandomAccess interface identifies List implementations which are faster to iterate using the List.get() method rather than using the Iterator.next() method.
  • 22. Working with maps • Map interface: • Map interface is used to map keys to value. • A map cannot contain duplicate keys, each key can map to at most one value. • A key is an object that is used to retrieve a value later. • Given a key and a value, one can store the value in a map object. • The value can be retrieved using the key. • The get() and put() are two basic operations in map interface • The put() is used to put a value into the map • The get() is used to obtain a value passing the key as an argument
  • 23. Methods provided by map interface Method Description Void clear() Removes all mappings from this map Boolean containsKey(Object key) Returns true if the map contains a mapping for the specified key Boolean containsValue(Object key) Returns true if this map maps one or more keys to the specified value. Set entrySet() Returns a set view of the mappings contained in this map Boolean equals(Object o) Compares the specified object with this map for equality Object get(Object key) Returns the value to which this map mpas the specified key
  • 24. Cont’d Method Description Int hashCode() Returns the hash code value for this map Boolean isEmpty() Returns true if this map contains no key-value mappings Set keyset() Returns a set view of the keys contained in this map Object put(Object key, Object value) Associates the specified value with the specified key in this map Void putAll(Map t) Copies all of the mappings from the specified map to this map Object remove(Object key) Removes the mappings for this key from this map if it is present Int size() Returns number of key-value mappings in this map Collection values() Returns a collection view of the values contained in the map
  • 25. HashMap class • HashMap class is used for hash table based implementation of the map interface. • This implementation provides all the optional map operations and permits null values and the null key. • The HashMap class has two parameters • Capacity – the capacity is the number of buckets in the hash table • Load factor – is the measure of how full the hash table is allowed to get before its capacity is automatically increased