SlideShare a Scribd company logo
2
Most read
10
Most read
Collections FrameWork
ArrayDqueue
Sorting & Reverse Techniques
Collections Framework
• The Java Collections Framework is a collection of interfaces and classes
which helps in storing and processing the data efficiently
• This framework has several useful classes which have tons of useful
functions which makes a programmer task super easy.
List
• A List is an ordered Collection (sometimes called a sequence)
• Lists may contain duplicate elements.
• Elements can be inserted or accessed by their position in the list, using a
zero-based index.
ArrayList
• ArrayList is a resizable-array implementation of the List interface.
• It implements all optional list operations, and permits all elements,
including null.
• this class provides methods to manipulate the size of the array that is used
internally to store the list
• Example program for ArrayList
LinkedList
• LinkedList is a doubly-linked list implementation of
the List and Deque interfaces
• The LinkedList class extends AbstractSequentialList and implements the List
interface
• It provides a linked-list data structure.
• Example of LinkedList
Difference between ArrayList and
LinkedList
• Since Array is an index based data-structure searching or getting element
from Array with index is pretty fast. Array provides O(1) performance for
get(index) method but remove is costly in ArrayList as you need to
rearrange all elements. On the Other hand LinkedList doesn't provide
Random or index based access and you need to iterate over linked list to
retrieve any element which is of order O(n).
• LinkedList has more memory overhead than ArrayList because in ArrayList
each index only holds actual object (data) but in case of LinkedList each
node holds both data and address of next and previous node.
Set Interface
• A Set is a Collection that cannot contain
duplicate elements
• .There are three main implementations of Set
interface: HashSet, TreeSet, LinkedHashSet
HashSet
• HashSet extends AbstractSet and implements the Set interface.
• It creates a collection that uses a hash table for storage.
• A hash table stores information by using a mechanism called hashing.
• In hashing, the informational content of a key is used to determine a
unique value, called its hash code.
• The hash code is then used as the index at which the data associated with
the key is stored
• Keypoints of HashSet
• HashSet doesn’t maintain any order
• HashSet doesn’t allow duplicates
• HashSet allows null values however if you insert more than one nulls it
would still return only one null value
• Example Program
Tree Set Class
• TreeSet is similar to HashSet except that it
sorts the elements in the ascending order
• TreeSet does not allows null element
• Example Program
LinkedHashSet
• LinkedHashSet is also an implementation of
Set interface
• LinkedHashSet maintains the insertion order.
Elements gets sorted in the same sequence in
which they have been added to the Set.
• Example program
ArrayDeque Class
• java.util.ArrayDeque implements a double-ended queue, which allows
efficient insertion and deletion at both ends.
• ArrayDeque is a resizable array implementation of the Deque interface
• It will perform faster than stack when used as stack and faster than linked
list when used access by multiple threads
• Null elements are prohibited.
• Example program
Sorting
import java.util.ArrayList;
import java.util.Collections;
public class Sorting_Array_List {
public static void main(String[] args) {
ArrayList<Integer> Integer_sort=new ArrayList<Integer>();
In`teger_sort.add(1); Integer_sort.add(0);
Integer_sort.add(8); Integer_sort.add(3);
//the output will show unsorted integers
System.out.println("Before sorting"+Integer_sort);
//now sorting the integers
Collections.sort(Integer_sort);
System.out.println("After sorting"+Integer_sort);
//we can access this collection with iterator also
}
}
####output####
Before sorting[1, 0, 8, 3]
After sorting[0, 1, 3, 8]
Reverse
import java.util.ArrayList;
import java.util.Collections;
public class Reverse_ArrayList {
public static void main(String[] args) {
ArrayList<Integer> Integer_sort=new ArrayList<Integer>();
Integer_sort.add(1);
Integer_sort.add(2);
Integer_sort.add(3);
Integer_sort.add(4);
//the output will show sorted integers
System.out.println("Before reverse"+Integer_sort);
//now reverse the integers
Collections.reverse(Integer_sort);
System.out.println("After sorting"+Integer_sort);
//we can access this collection with iterator also
}
}
####output####
Before reverse[1, 2, 3, 4]
After sorting[4, 3, 2, 1]

More Related Content

What's hot (20)

PPT
L11 array list
teach4uin
 
PPTX
Java Stack Data Structure.pptx
vishal choudhary
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PPT
Java collections concept
kumar gaurav
 
PDF
Collections Api - Java
Drishti Bhalla
 
PPT
Collection Framework in java
CPD INDIA
 
PDF
Java Collections Tutorials
Prof. Erwin Globio
 
PDF
Java ArrayList Tutorial | Edureka
Edureka!
 
ODP
Introduction to Java 8
Knoldus Inc.
 
PDF
07 java collection
Abhishek Khune
 
PPTX
ArrayList in JAVA
SAGARDAVE29
 
PPT
sets and maps
Rajkattamuri
 
PDF
Java collections
Hamid Ghorbani
 
PPTX
Java Stack Data Structure.pptx
vishal choudhary
 
PDF
Arrays in Java
Naz Abdalla
 
PPT
Abstract class in java
Lovely Professional University
 
PDF
Java 8 Lambda Expressions
Scott Leberknight
 
PPTX
Hibernate ppt
Aneega
 
PPT
Inheritance in java
Lovely Professional University
 
L11 array list
teach4uin
 
Java Stack Data Structure.pptx
vishal choudhary
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Java collections concept
kumar gaurav
 
Collections Api - Java
Drishti Bhalla
 
Collection Framework in java
CPD INDIA
 
Java Collections Tutorials
Prof. Erwin Globio
 
Java ArrayList Tutorial | Edureka
Edureka!
 
Introduction to Java 8
Knoldus Inc.
 
07 java collection
Abhishek Khune
 
ArrayList in JAVA
SAGARDAVE29
 
sets and maps
Rajkattamuri
 
Java collections
Hamid Ghorbani
 
Java Stack Data Structure.pptx
vishal choudhary
 
Arrays in Java
Naz Abdalla
 
Abstract class in java
Lovely Professional University
 
Java 8 Lambda Expressions
Scott Leberknight
 
Hibernate ppt
Aneega
 
Inheritance in java
Lovely Professional University
 

Similar to Collections framework in java (20)

PPTX
ArrayList in JAVA
SAGARDAVE29
 
PPTX
Java util
Srikrishna k
 
PPTX
Collections Training
Ramindu Deshapriya
 
PPTX
Java Collections Framework - Interfaces, Classes and Algorithms
RajalakshmiS74
 
PPTX
collection framework.pptx
SoniaKapoor56
 
PPTX
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
PPTX
Javasession7
Rajeev Kumar
 
PPTX
Advanced Java - UNIT 3.pptx
eyemitra1
 
PPTX
Presentation.pptx on java oops concepts jcf
SoumyaSou4
 
PPT
11000121065_NAITIK CHATTERJEE.ppt
NaitikChatterjee
 
PPTX
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
PPT
Md08 collection api
Rakesh Madugula
 
PPTX
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
PPTX
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
logesswarisrinivasan
 
PDF
Java collections-interview-questions
yearninginjava
 
PDF
Java collections
padmad2291
 
PPTX
Java_Collections_Framework_Presentation.pptx
abhishekhatwal18
 
PDF
Lecture 8_٠٨٣٣٣٦taiz unvercity object oreinted programming.pdf
nabeehmohammedtaher
 
PPTX
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Sagar Verma
 
PPTX
Java collections
Sujit Kumar
 
ArrayList in JAVA
SAGARDAVE29
 
Java util
Srikrishna k
 
Collections Training
Ramindu Deshapriya
 
Java Collections Framework - Interfaces, Classes and Algorithms
RajalakshmiS74
 
collection framework.pptx
SoniaKapoor56
 
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
Javasession7
Rajeev Kumar
 
Advanced Java - UNIT 3.pptx
eyemitra1
 
Presentation.pptx on java oops concepts jcf
SoumyaSou4
 
11000121065_NAITIK CHATTERJEE.ppt
NaitikChatterjee
 
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
Md08 collection api
Rakesh Madugula
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
logesswarisrinivasan
 
Java collections-interview-questions
yearninginjava
 
Java collections
padmad2291
 
Java_Collections_Framework_Presentation.pptx
abhishekhatwal18
 
Lecture 8_٠٨٣٣٣٦taiz unvercity object oreinted programming.pdf
nabeehmohammedtaher
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Sagar Verma
 
Java collections
Sujit Kumar
 
Ad

More from yugandhar vadlamudi (15)

ODP
Toolbarexample
yugandhar vadlamudi
 
ODP
Singleton pattern
yugandhar vadlamudi
 
PPT
Object Relational model for SQLIite in android
yugandhar vadlamudi
 
DOCX
JButton in Java Swing example
yugandhar vadlamudi
 
PPTX
Packaes & interfaces
yugandhar vadlamudi
 
PPTX
Exception handling in java
yugandhar vadlamudi
 
DOCX
JMenu Creation in Java Swing
yugandhar vadlamudi
 
DOCX
Adding a action listener to button
yugandhar vadlamudi
 
PPTX
Dynamic method dispatch
yugandhar vadlamudi
 
PPTX
Operators in java
yugandhar vadlamudi
 
PPTX
Inheritance
yugandhar vadlamudi
 
PPTX
Control flow statements in java
yugandhar vadlamudi
 
PPTX
Closer look at classes
yugandhar vadlamudi
 
PPTX
java Applet Introduction
yugandhar vadlamudi
 
PPTX
Class introduction in java
yugandhar vadlamudi
 
Toolbarexample
yugandhar vadlamudi
 
Singleton pattern
yugandhar vadlamudi
 
Object Relational model for SQLIite in android
yugandhar vadlamudi
 
JButton in Java Swing example
yugandhar vadlamudi
 
Packaes & interfaces
yugandhar vadlamudi
 
Exception handling in java
yugandhar vadlamudi
 
JMenu Creation in Java Swing
yugandhar vadlamudi
 
Adding a action listener to button
yugandhar vadlamudi
 
Dynamic method dispatch
yugandhar vadlamudi
 
Operators in java
yugandhar vadlamudi
 
Inheritance
yugandhar vadlamudi
 
Control flow statements in java
yugandhar vadlamudi
 
Closer look at classes
yugandhar vadlamudi
 
java Applet Introduction
yugandhar vadlamudi
 
Class introduction in java
yugandhar vadlamudi
 
Ad

Recently uploaded (20)

PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Introduction to Indian Writing in English
Trushali Dodiya
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 

Collections framework in java

  • 2. Collections Framework • The Java Collections Framework is a collection of interfaces and classes which helps in storing and processing the data efficiently • This framework has several useful classes which have tons of useful functions which makes a programmer task super easy.
  • 3. List • A List is an ordered Collection (sometimes called a sequence) • Lists may contain duplicate elements. • Elements can be inserted or accessed by their position in the list, using a zero-based index.
  • 4. ArrayList • ArrayList is a resizable-array implementation of the List interface. • It implements all optional list operations, and permits all elements, including null. • this class provides methods to manipulate the size of the array that is used internally to store the list • Example program for ArrayList
  • 5. LinkedList • LinkedList is a doubly-linked list implementation of the List and Deque interfaces • The LinkedList class extends AbstractSequentialList and implements the List interface • It provides a linked-list data structure. • Example of LinkedList
  • 6. Difference between ArrayList and LinkedList • Since Array is an index based data-structure searching or getting element from Array with index is pretty fast. Array provides O(1) performance for get(index) method but remove is costly in ArrayList as you need to rearrange all elements. On the Other hand LinkedList doesn't provide Random or index based access and you need to iterate over linked list to retrieve any element which is of order O(n). • LinkedList has more memory overhead than ArrayList because in ArrayList each index only holds actual object (data) but in case of LinkedList each node holds both data and address of next and previous node.
  • 7. Set Interface • A Set is a Collection that cannot contain duplicate elements • .There are three main implementations of Set interface: HashSet, TreeSet, LinkedHashSet
  • 8. HashSet • HashSet extends AbstractSet and implements the Set interface. • It creates a collection that uses a hash table for storage. • A hash table stores information by using a mechanism called hashing. • In hashing, the informational content of a key is used to determine a unique value, called its hash code. • The hash code is then used as the index at which the data associated with the key is stored • Keypoints of HashSet • HashSet doesn’t maintain any order • HashSet doesn’t allow duplicates • HashSet allows null values however if you insert more than one nulls it would still return only one null value • Example Program
  • 9. Tree Set Class • TreeSet is similar to HashSet except that it sorts the elements in the ascending order • TreeSet does not allows null element • Example Program
  • 10. LinkedHashSet • LinkedHashSet is also an implementation of Set interface • LinkedHashSet maintains the insertion order. Elements gets sorted in the same sequence in which they have been added to the Set. • Example program
  • 11. ArrayDeque Class • java.util.ArrayDeque implements a double-ended queue, which allows efficient insertion and deletion at both ends. • ArrayDeque is a resizable array implementation of the Deque interface • It will perform faster than stack when used as stack and faster than linked list when used access by multiple threads • Null elements are prohibited. • Example program
  • 12. Sorting import java.util.ArrayList; import java.util.Collections; public class Sorting_Array_List { public static void main(String[] args) { ArrayList<Integer> Integer_sort=new ArrayList<Integer>(); In`teger_sort.add(1); Integer_sort.add(0); Integer_sort.add(8); Integer_sort.add(3); //the output will show unsorted integers System.out.println("Before sorting"+Integer_sort); //now sorting the integers Collections.sort(Integer_sort); System.out.println("After sorting"+Integer_sort); //we can access this collection with iterator also } } ####output#### Before sorting[1, 0, 8, 3] After sorting[0, 1, 3, 8]
  • 13. Reverse import java.util.ArrayList; import java.util.Collections; public class Reverse_ArrayList { public static void main(String[] args) { ArrayList<Integer> Integer_sort=new ArrayList<Integer>(); Integer_sort.add(1); Integer_sort.add(2); Integer_sort.add(3); Integer_sort.add(4); //the output will show sorted integers System.out.println("Before reverse"+Integer_sort); //now reverse the integers Collections.reverse(Integer_sort); System.out.println("After sorting"+Integer_sort); //we can access this collection with iterator also } } ####output#### Before reverse[1, 2, 3, 4] After sorting[4, 3, 2, 1]