SlideShare uma empresa Scribd logo
1 de 23
The Collection Framework
Collections Framework


 A collection is a group of objects.
 The Collection Framework Standardizes the way in
 which group of objects are handled by your program.

What c++ calls a Container,Java calls a Collection
The Collection interfaces


 Collection- enable you to work with groups of
 objects.

 List- extends collection to handle sequences.


 Set- extends collection to handle sets, which must
 contain unique elements.
The Collection Classes


 ArrayList – implements a dynamic array.
 LinkedList – implements a linked list.
 HashSet – uses hash table.
 linkedHashSet – allow insertion-order iterations.
 TreeSet – implements a set stored in a tree.
ArrayList class


 ArrayList class implements the List interface.
 ArrayList supports dynamic arrays that can grow as needed.
 It is a Variable length array of object references.


 ArrayLists are created with an initial size. When this size is
  enlarged, the collection is automatically enlarged. And when the
  objects are removed, the array may be shrunk.
Using constructor


 ArrayList()
 ArrayList(Collection c)
 ArrayList(int capacity)
Methods and Examples

 Create an array list
       ArrayList a1 = new ArrayList();

 Add elements to the array list
      a1.add(“c”);
      a1.add(1,“A2”);
 Display the array list
    System.out.println(a1);

 Remove elements from the array list
    a1.remove(“F”);
    a1.remove(2);

 For finding the size of arrayList
      a1.size();
Obtaining an Array from an ArrayList


 Add elements to the array list
   a1.add(new Integer(1));

 Get array
    object ia[ ] = a1.toArray();
LinkedList Class


 LinkedList class extends AbstractSequentialList and
 implements the List interface.

 It provides a linked list data structure.
Constructor


 LinkedList()


 LinkedList(collection c)
Methods

 To add elements at the first /last position.
        addFirst();
        addLast();

 To retrieve the elements at first /last position.
        getFirst();
        getLast();

 To remove the elements at first /last position.
        removeFirst();
        removeLast();
TreeSet class


 TreeSet provides an implementations of the Set
 interface that uses a tree for storage.

 Objects are stored in sorted order i.e ascending
 order.

 Access and retrieval times are quite fast.
Constructors

 TreeSet()
 TreeSet(collection c)
 TreeSet(comparator comp)
 TreeSet(SortedSet ss)
Example

Import java.util.*;
Class TreeSetDemo
{
Public static void main(String args[])
{
TreeSet ts=new TreeSet();
ts.add(“C”);
ts.add(“A”);
ts.add(“B”);
System.out.println(ts);
}
}

Output-    [A,B,C]
HashSet class

 HashSet extends AbstractSet and implements the Set
  interface.
 It creates a collection that uses a hash table for storage.
 Basic operations:
                        add()
                        contains()
                        remove()
                        size()
Using constructor

 HashSet()
 HashSet(collection c)
 HashSet(int capacity)
 HashSet(int capacity, float fillRatio)
Methods

 boolean add(Object o)
 void clear()
 Object clone()
 boolean contains(Object o)
 boolean isEmpty()
 Iterator iterator()
 boolean remove(Object o)
 int size()
Example

import java.util.*;
class hashset
{
public static void main(String args[])
{
HashSet hs = new HashSet();
hs.add("B");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("F");
System.out.println(hs);
hs.remove("C");
System.out.println("elements after removing C"+hs);
 }
 }
LinkedHashSet class


 LinkedHashSet extends HashSet, but adds no
  members of its own.
 LinkedHashSet maintains a linked list of the entries
  in the set.
Using constructor


 LinkedHashSet( )
 LinkedHashSet(Collection c)
 LinkedHashSet(int capacity)
 LinkedHashSet(int capacity, float fillRatio)
Remove all elements from LinkedHashSet

import java.util.LinkedHashSet;
 public class linkedhashset
 {
   public static void main(String[] args)
     {
      LinkedHashSet lhashSet = new LinkedHashSet();
         lhashSet.add(new Integer("1"));
         lhashSet.add(new Integer("2"));
         lhashSet.add(new Integer("3"));
     System.out.println("LinkedHashSet before removal : " + lhashSet);
         lhashSet.clear();
     System.out.println("LinkedHashSet after removal : " + lhashSet);
     System.out.println("Is LinkedHashSet empty ? " + lhashSet.isEmpty());
   }
}
House Is Open For Queries

Mais conteúdo relacionado

Mais procurados

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptxvishal choudhary
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 
Java collections concept
Java collections conceptJava collections concept
Java collections conceptkumar gaurav
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in javaVishnu Suresh
 
L11 array list
L11 array listL11 array list
L11 array listteach4uin
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events WebStackAcademy
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)Partnered Health
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in javaHrithikShinde
 

Mais procurados (20)

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Generics
GenericsGenerics
Generics
 
Web api
Web apiWeb api
Web api
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
L11 array list
L11 array listL11 array list
L11 array list
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 

Destaque

Detailed description about Hubs Switches Modems and their working
Detailed description about  Hubs Switches Modems and their workingDetailed description about  Hubs Switches Modems and their working
Detailed description about Hubs Switches Modems and their workingrockingprashik
 
Functional block diagram_of_laser_printer
Functional block diagram_of_laser_printerFunctional block diagram_of_laser_printer
Functional block diagram_of_laser_printerKartik Kalpande Patil
 

Destaque (8)

Detailed description about Hubs Switches Modems and their working
Detailed description about  Hubs Switches Modems and their workingDetailed description about  Hubs Switches Modems and their working
Detailed description about Hubs Switches Modems and their working
 
Functional block diagram_of_laser_printer
Functional block diagram_of_laser_printerFunctional block diagram_of_laser_printer
Functional block diagram_of_laser_printer
 
Pptemail
PptemailPptemail
Pptemail
 
Modem
ModemModem
Modem
 
Introduction to modem
Introduction to modemIntroduction to modem
Introduction to modem
 
Modem
ModemModem
Modem
 
Presentation on modem
Presentation on modemPresentation on modem
Presentation on modem
 
Modem presentation
Modem presentationModem presentation
Modem presentation
 

Semelhante a Presentation1

Collections Framework
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaEdureka!
 
Collections generic
Collections genericCollections generic
Collections genericsandhish
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & setsRatnaJava
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)Janki Shah
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work pptRanjith Alappadan
 
collection framework in java
collection framework in javacollection framework in java
collection framework in javaMANOJ KUMAR
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionssuseredfbe9
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & CollectionArya
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & CollectionArya
 

Semelhante a Presentation1 (20)

Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
07 java collection
07 java collection07 java collection
07 java collection
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
20 ch22 collections
20 ch22 collections20 ch22 collections
20 ch22 collections
 
Collections
CollectionsCollections
Collections
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Collections generic
Collections genericCollections generic
Collections generic
 
16 containers
16   containers16   containers
16 containers
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
Java.util
Java.utilJava.util
Java.util
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & Collection
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & Collection
 

Mais de Anand Grewal

Mais de Anand Grewal (12)

distributed dbms
distributed dbmsdistributed dbms
distributed dbms
 
Transaction concurrency control
Transaction concurrency controlTransaction concurrency control
Transaction concurrency control
 
Object modeling
Object modelingObject modeling
Object modeling
 
Object analysis and design
Object analysis and designObject analysis and design
Object analysis and design
 
Object modeling
Object modelingObject modeling
Object modeling
 
O ops concepts
O ops conceptsO ops concepts
O ops concepts
 
System design
System designSystem design
System design
 
Presentation12
Presentation12Presentation12
Presentation12
 
Event handling
Event handlingEvent handling
Event handling
 
Isp
IspIsp
Isp
 
Java
JavaJava
Java
 
Presentation on dns
Presentation on dnsPresentation on dns
Presentation on dns
 

Último

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 

Último (20)

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 

Presentation1

  • 2. Collections Framework  A collection is a group of objects.  The Collection Framework Standardizes the way in which group of objects are handled by your program. What c++ calls a Container,Java calls a Collection
  • 3. The Collection interfaces  Collection- enable you to work with groups of objects.  List- extends collection to handle sequences.  Set- extends collection to handle sets, which must contain unique elements.
  • 4. The Collection Classes  ArrayList – implements a dynamic array.  LinkedList – implements a linked list.  HashSet – uses hash table.  linkedHashSet – allow insertion-order iterations.  TreeSet – implements a set stored in a tree.
  • 5. ArrayList class  ArrayList class implements the List interface.  ArrayList supports dynamic arrays that can grow as needed.  It is a Variable length array of object references.  ArrayLists are created with an initial size. When this size is enlarged, the collection is automatically enlarged. And when the objects are removed, the array may be shrunk.
  • 6. Using constructor  ArrayList()  ArrayList(Collection c)  ArrayList(int capacity)
  • 7. Methods and Examples  Create an array list ArrayList a1 = new ArrayList();  Add elements to the array list a1.add(“c”); a1.add(1,“A2”);
  • 8.  Display the array list System.out.println(a1);  Remove elements from the array list a1.remove(“F”); a1.remove(2);  For finding the size of arrayList a1.size();
  • 9. Obtaining an Array from an ArrayList  Add elements to the array list a1.add(new Integer(1));  Get array object ia[ ] = a1.toArray();
  • 10. LinkedList Class  LinkedList class extends AbstractSequentialList and implements the List interface.  It provides a linked list data structure.
  • 12. Methods  To add elements at the first /last position. addFirst(); addLast();  To retrieve the elements at first /last position. getFirst(); getLast();  To remove the elements at first /last position. removeFirst(); removeLast();
  • 13. TreeSet class  TreeSet provides an implementations of the Set interface that uses a tree for storage.  Objects are stored in sorted order i.e ascending order.  Access and retrieval times are quite fast.
  • 14. Constructors  TreeSet()  TreeSet(collection c)  TreeSet(comparator comp)  TreeSet(SortedSet ss)
  • 15. Example Import java.util.*; Class TreeSetDemo { Public static void main(String args[]) { TreeSet ts=new TreeSet(); ts.add(“C”); ts.add(“A”); ts.add(“B”); System.out.println(ts); } } Output- [A,B,C]
  • 16. HashSet class  HashSet extends AbstractSet and implements the Set interface.  It creates a collection that uses a hash table for storage.  Basic operations: add() contains() remove() size()
  • 17. Using constructor  HashSet()  HashSet(collection c)  HashSet(int capacity)  HashSet(int capacity, float fillRatio)
  • 18. Methods  boolean add(Object o)  void clear()  Object clone()  boolean contains(Object o)  boolean isEmpty()  Iterator iterator()  boolean remove(Object o)  int size()
  • 19. Example import java.util.*; class hashset { public static void main(String args[]) { HashSet hs = new HashSet(); hs.add("B"); hs.add("A"); hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); System.out.println(hs); hs.remove("C"); System.out.println("elements after removing C"+hs); } }
  • 20. LinkedHashSet class  LinkedHashSet extends HashSet, but adds no members of its own.  LinkedHashSet maintains a linked list of the entries in the set.
  • 21. Using constructor  LinkedHashSet( )  LinkedHashSet(Collection c)  LinkedHashSet(int capacity)  LinkedHashSet(int capacity, float fillRatio)
  • 22. Remove all elements from LinkedHashSet import java.util.LinkedHashSet; public class linkedhashset { public static void main(String[] args) { LinkedHashSet lhashSet = new LinkedHashSet(); lhashSet.add(new Integer("1")); lhashSet.add(new Integer("2")); lhashSet.add(new Integer("3")); System.out.println("LinkedHashSet before removal : " + lhashSet); lhashSet.clear(); System.out.println("LinkedHashSet after removal : " + lhashSet); System.out.println("Is LinkedHashSet empty ? " + lhashSet.isEmpty()); } }
  • 23. House Is Open For Queries