SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Advanced Java Programming
ArrayList, LinkedList ,Vector and Stack
By
Ravi Kant Sahu
Asst. Professor, LPU
ArrAyList
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
ArrayList
• The ArrayList class extends AbstractList and implements the List
interface.
• Defined in java.util package.
• ArrayList supports dynamic arrays that can grow as needed.
• Array lists are created with an initial size.
• When this size is exceeded, the collection is automatically enlarged.
• When objects are removed, the array may be shrunk.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
ArrayList Constructors
• T he ArrayList class supports three constructors.
 ArrayList() : creates an empty array list with an initial capacity
sufficient to hold 10 elements.
 ArrayList(int capacity) : creates an array list that has the
specified initial capacity.
 ArrayList(Collection c) : creates an array list that is initialized
with the elements of the collection c.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of ArrayList
boolean add(Object o)
• Appends the specified element to the end of this list.
void add(int index, Object element)
• Inserts the specified element at the specified position index in
this list.
• Throws IndexOutOfBoundsException if the specified index is
out of range.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
boolean addAll(Collection c )
• Appends all of the elements in the specified collection to the end of
this list.
• Throws NullPointerException if the specified collection is null.
boolean addAll(int index, Collection c )
• Inserts all of the elements of the specified collection into this list,
starting at the specified position.
• Throws NullPointerException if the specified collection is null.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
void clear()
• Removes all of the elements from this list.
Object remove(int index)
• Removes the element at the specified position in this list.
Object clone()
• Returns a shallow copy of this ArrayList.
int size()
• Returns the number of elements in the list.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
boolean contains(Object o)
• Returns true if this list contains the specified element.
Object get(int index)
• Returns the element at the specified position in this list.
int indexOf(Object o)
• Returns the index in this list of the first occurrence of the
specified element, or -1 if the List does not contain the element.
int lastIndexOf(Object o)
• Returns the index in this list of the last occurrence of the
specified element, or -1.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
void ensureCapacity(int minCapacity)
• Increases the capacity of this ArrayList instance, if necessary,
to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
Object set(int index, Object element)
• Replaces the element at the specified position in this list with
the specified element.
• Throws IndexOutOfBoundsException if the specified index is
out of range (index < 0 || index >= size()).
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
void trimToSize()
• Trims the capacity of this ArrayList instance to be the list’s
current size.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
LinkedList
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
LinkedList
• LinkedList stores elements in a linked list.
• Insertion or deletion of elements at the beginning of the list.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
LinkedList Constructors
• T he LinkedList class supports two constructors.
 LinkedList() : creates an empty list with an initial capacity
sufficient to hold 10 elements.
 LinkedList(Collection c) : creates an array list that is
initialized with the elements of the collection c.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of LinkedList
• void addFirst(Object o)
• void addLast(Object o)
• Object getFirst()
• Object getLast()
• Object removeFirst()
• Object removeLast()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Difference b/w LinkedList and ArrayList
• The critical difference between them pertains to internal
implementation, which affects their performance.
• ArrayList is efficient for retrieving elements and LinkedList is
efficient for inserting and removing elements at the beginning
of the list.
• Both have the same performance for inserting and removing
elements in the middle or at the end of the list.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Vector
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Vector
• Vector is a subclass of AbstractList.
• Vector is the same as ArrayList, except that it contains
synchronized methods for accessing and modifying the vector.
• Synchronized methods can prevent data corruption when a
vector is accessed and modified by two or more threads
concurrently.
• Applications that do not require synchronization, using
ArrayList is more efficient than using Vector.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Vector Constructors
• Vector class supports following constructors.
 Vector()
 Vector(Collection c) :
 Vector(int capacity)
 Vector(int capacity, int increment): Creates a vector with the
specified initial capacity and increment.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of Vector
• void addElement (Object o)
• void elementAt(int index)
• Enumerations elements()
• void ensureCapacity(int capacity)
• Object firstElement()
• Object lastElement()
• void insertElementAt(Object o, int index)
• int capacity()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of Vector
• void copyInto(Object [])
• void removeAllElements()
• void removeElement(Object o)
• void removeElementAt(int index)
• setElementAt(Object o, int index)
• setSize(int size)
• void trimToSize()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Difference b/w Vector and ArrayList
• Vector is synchronized where as ArrayList is not.
• ArrayList supports Iterator and ListIterator whereas Vector
supports Enumeration and Iterator.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Stack
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Stack
• Vector and Stack are the legacy classes.
• There were introduced prior to Java 2.
• Stack is a subclass of Vector.
• Stack class defines the default constructor only:
Stack()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of Stack
• boolean empty()
• Object peek()
• Object pop()
• Object push(Object o)
• int search(Object o) : Returns the position of the specified
element in this stack.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
List classes

Más contenido relacionado

La actualidad más candente

Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanZeeshan Khan
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and VariablesNilesh Dalvi
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objectsmaznabili
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to DatastructureNilesh Dalvi
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and IntefacesNilesh Dalvi
 
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!
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception HandlingNilesh Dalvi
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classesteach4uin
 

La actualidad más candente (20)

Java Collections
Java  Collections Java  Collections
Java Collections
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
 
8. String
8. String8. String
8. String
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to Datastructure
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Overview of Java
Overview of Java Overview of Java
Overview of Java
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
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...
 
Hemajava
HemajavaHemajava
Hemajava
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
 

Destacado (14)

Packages
PackagesPackages
Packages
 
Sms several papers
Sms several papersSms several papers
Sms several papers
 
Networking
NetworkingNetworking
Networking
 
Jun 2012(1)
Jun 2012(1)Jun 2012(1)
Jun 2012(1)
 
Event handling
Event handlingEvent handling
Event handling
 
Jdbc
JdbcJdbc
Jdbc
 
Multi threading
Multi threadingMulti threading
Multi threading
 
Questions for Class I & II
Questions for Class I & IIQuestions for Class I & II
Questions for Class I & II
 
Servlets
ServletsServlets
Servlets
 
Basic IO
Basic IOBasic IO
Basic IO
 
Swing api
Swing apiSwing api
Swing api
 
Internationalization
InternationalizationInternationalization
Internationalization
 
Distributed Programming (RMI)
Distributed Programming (RMI)Distributed Programming (RMI)
Distributed Programming (RMI)
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 

Similar a List classes

Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40bhawna sharma
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & setsRatnaJava
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptRithwikRanjan
 
L11 array list
L11 array listL11 array list
L11 array listteach4uin
 
ArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxAbid523408
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )charan kumar
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructorsRavi_Kant_Sahu
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxeyemitra1
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections frameworkRavi Chythanya
 

Similar a List classes (20)

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
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Java collections
Java collectionsJava collections
Java collections
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
 
L11 array list
L11 array listL11 array list
L11 array list
 
ArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxArrayList class and useful methods.pptx
ArrayList class and useful methods.pptx
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
Java util
Java utilJava util
Java util
 
Java keywords
Java keywordsJava keywords
Java keywords
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructors
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 

Más de Ravi_Kant_Sahu

Common Programming Errors by Beginners in Java
Common Programming Errors by Beginners in JavaCommon Programming Errors by Beginners in Java
Common Programming Errors by Beginners in JavaRavi_Kant_Sahu
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)Ravi_Kant_Sahu
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi_Kant_Sahu
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in JavaRavi_Kant_Sahu
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 

Más de Ravi_Kant_Sahu (10)

Common Programming Errors by Beginners in Java
Common Programming Errors by Beginners in JavaCommon Programming Errors by Beginners in Java
Common Programming Errors by Beginners in Java
 
Gui programming (awt)
Gui programming (awt)Gui programming (awt)
Gui programming (awt)
 
Event handling
Event handlingEvent handling
Event handling
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
Packages
PackagesPackages
Packages
 
Inheritance
InheritanceInheritance
Inheritance
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 

Último

Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5DianaGray10
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementNuwan Dias
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024Alexander Turgeon
 

Último (20)

Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API Management
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024Valere | Digital Solutions & AI Transformation Portfolio | 2024
Valere | Digital Solutions & AI Transformation Portfolio | 2024
 

List classes

  • 1. Advanced Java Programming ArrayList, LinkedList ,Vector and Stack By Ravi Kant Sahu Asst. Professor, LPU
  • 2. ArrAyList Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 3. ArrayList • The ArrayList class extends AbstractList and implements the List interface. • Defined in java.util package. • ArrayList supports dynamic arrays that can grow as needed. • Array lists are created with an initial size. • When this size is exceeded, the collection is automatically enlarged. • When objects are removed, the array may be shrunk. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 4. ArrayList Constructors • T he ArrayList class supports three constructors.  ArrayList() : creates an empty array list with an initial capacity sufficient to hold 10 elements.  ArrayList(int capacity) : creates an array list that has the specified initial capacity.  ArrayList(Collection c) : creates an array list that is initialized with the elements of the collection c. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 5. Methods of ArrayList boolean add(Object o) • Appends the specified element to the end of this list. void add(int index, Object element) • Inserts the specified element at the specified position index in this list. • Throws IndexOutOfBoundsException if the specified index is out of range. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 6. boolean addAll(Collection c ) • Appends all of the elements in the specified collection to the end of this list. • Throws NullPointerException if the specified collection is null. boolean addAll(int index, Collection c ) • Inserts all of the elements of the specified collection into this list, starting at the specified position. • Throws NullPointerException if the specified collection is null. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 7. void clear() • Removes all of the elements from this list. Object remove(int index) • Removes the element at the specified position in this list. Object clone() • Returns a shallow copy of this ArrayList. int size() • Returns the number of elements in the list. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 8. boolean contains(Object o) • Returns true if this list contains the specified element. Object get(int index) • Returns the element at the specified position in this list. int indexOf(Object o) • Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain the element. int lastIndexOf(Object o) • Returns the index in this list of the last occurrence of the specified element, or -1. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 9. void ensureCapacity(int minCapacity) • Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. Object set(int index, Object element) • Replaces the element at the specified position in this list with the specified element. • Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()). Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 10. void trimToSize() • Trims the capacity of this ArrayList instance to be the list’s current size. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 11. LinkedList Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 12. LinkedList • LinkedList stores elements in a linked list. • Insertion or deletion of elements at the beginning of the list. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 13. LinkedList Constructors • T he LinkedList class supports two constructors.  LinkedList() : creates an empty list with an initial capacity sufficient to hold 10 elements.  LinkedList(Collection c) : creates an array list that is initialized with the elements of the collection c. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 14. Methods of LinkedList • void addFirst(Object o) • void addLast(Object o) • Object getFirst() • Object getLast() • Object removeFirst() • Object removeLast() Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 15. Difference b/w LinkedList and ArrayList • The critical difference between them pertains to internal implementation, which affects their performance. • ArrayList is efficient for retrieving elements and LinkedList is efficient for inserting and removing elements at the beginning of the list. • Both have the same performance for inserting and removing elements in the middle or at the end of the list. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 16. Vector Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 17. Vector • Vector is a subclass of AbstractList. • Vector is the same as ArrayList, except that it contains synchronized methods for accessing and modifying the vector. • Synchronized methods can prevent data corruption when a vector is accessed and modified by two or more threads concurrently. • Applications that do not require synchronization, using ArrayList is more efficient than using Vector. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 18. Vector Constructors • Vector class supports following constructors.  Vector()  Vector(Collection c) :  Vector(int capacity)  Vector(int capacity, int increment): Creates a vector with the specified initial capacity and increment. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 19. Methods of Vector • void addElement (Object o) • void elementAt(int index) • Enumerations elements() • void ensureCapacity(int capacity) • Object firstElement() • Object lastElement() • void insertElementAt(Object o, int index) • int capacity() Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 20. Methods of Vector • void copyInto(Object []) • void removeAllElements() • void removeElement(Object o) • void removeElementAt(int index) • setElementAt(Object o, int index) • setSize(int size) • void trimToSize() Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 21. Difference b/w Vector and ArrayList • Vector is synchronized where as ArrayList is not. • ArrayList supports Iterator and ListIterator whereas Vector supports Enumeration and Iterator. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 22. Stack Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 23. Stack • Vector and Stack are the legacy classes. • There were introduced prior to Java 2. • Stack is a subclass of Vector. • Stack class defines the default constructor only: Stack() Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 24. Methods of Stack • boolean empty() • Object peek() • Object pop() • Object push(Object o) • int search(Object o) : Returns the position of the specified element in this stack. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)