SlideShare a Scribd company logo
ArrayList
ArrayList Class
• The java.util.ArrayList class provides resizable array
and implements the List interface. Some important
points about ArrayList:
 It implements all optional list operations & it also
permits all elements includes null.
 It provides method to manipulate the size of the
array that is used internally to store the list.
 The constant factor is low compared to that for
the LinkedList implementation.
Methods of
Arraylist
https://docs.oracle.com/javase/7/d
ocs/api/java/util/ArrayList.html
JAVA ArrayList
• The difference between a built-in array and an ArrayList in Java, is that the size of an array
cannot be modified.
• If you want to add or remove elements to/from an array, you have to create a new one. While
elements can be added and removed from an ArrayList whenever you want.
• The syntax is also slightly different:
Create an ArrayList object called cars that will store strings:
ArrayList<String> cars = new ArrayList<String>(); // Create an ArrayList object
Example
• The ArrayList class has
many useful methods.
• In this example , use
the add() method to add
elements to the ArrayList:
Examples of
ArrayList
Methods
• To access an element in the ArrayList, use the get() method and
refer to the index number:
cars.get(0);
Note: Array indexes start with 0: [0] is the first element.[1] is the
second element, etc.
• To modify an element, use the set() method and refer to the index
number:
cars.set(0, "Opel");
• To remove an element, use the remove() method and refer to the
index number:
cars.remove(0);
• To remove all the elements in the ArrayList, use the clear()
method:
cars.clear();
• To find out how many elements an ArrayList have, use
the size method:
cars.size();
Thank You
Ad

More Related Content

What's hot (20)

Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
Hitesh-Java
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
Drishti Bhalla
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
Jussi Pohjolainen
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Lovely Professional University
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
sets and maps
 sets and maps sets and maps
sets and maps
Rajkattamuri
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
PhD Research Scholar
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
Binoj T E
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 

Similar to ArrayList in JAVA (20)

arraylist in java a comparison of the array and arraylist
arraylist in java a comparison of the array and arraylistarraylist in java a comparison of the array and arraylist
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answeredU-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
arraylistinjava.pptx
arraylistinjava.pptxarraylistinjava.pptx
arraylistinjava.pptx
dintakurthigayathri9
 
Java util
Java utilJava util
Java util
Srikrishna k
 
Collections Training
Collections TrainingCollections Training
Collections Training
Ramindu Deshapriya
 
Presentation.pptx on java oops concepts jcf
Presentation.pptx on java oops concepts jcfPresentation.pptx on java oops concepts jcf
Presentation.pptx on java oops concepts jcf
SoumyaSou4
 
VTUOOPMCA5THMODULECollection OverV .pptx
VTUOOPMCA5THMODULECollection OverV .pptxVTUOOPMCA5THMODULECollection OverV .pptx
VTUOOPMCA5THMODULECollection OverV .pptx
VeenaNaik23
 
mca5thCollection OverViCollection O.pptx
mca5thCollection OverViCollection O.pptxmca5thCollection OverViCollection O.pptx
mca5thCollection OverViCollection O.pptx
VeenaNaik23
 
VTUOOPMCA5THMODULECollection OverVi.pptx
VTUOOPMCA5THMODULECollection OverVi.pptxVTUOOPMCA5THMODULECollection OverVi.pptx
VTUOOPMCA5THMODULECollection OverVi.pptx
VeenaNaik23
 
VTUOOPMCA5THMODULEvCollection OverV.pptx
VTUOOPMCA5THMODULEvCollection OverV.pptxVTUOOPMCA5THMODULEvCollection OverV.pptx
VTUOOPMCA5THMODULEvCollection OverV.pptx
VeenaNaik23
 
Java Collections
Java CollectionsJava Collections
Java Collections
parag
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Collections
CollectionsCollections
Collections
Marwa Dosoky
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
talha ijaz
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
rangariprajwal4554
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
Dr. SURBHI SAROHA
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
Rakesh Madugula
 
Java collections
Java collectionsJava collections
Java collections
padmad2291
 
arraylist in java a comparison of the array and arraylist
arraylist in java a comparison of the array and arraylistarraylist in java a comparison of the array and arraylist
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answeredU-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
Presentation.pptx on java oops concepts jcf
Presentation.pptx on java oops concepts jcfPresentation.pptx on java oops concepts jcf
Presentation.pptx on java oops concepts jcf
SoumyaSou4
 
VTUOOPMCA5THMODULECollection OverV .pptx
VTUOOPMCA5THMODULECollection OverV .pptxVTUOOPMCA5THMODULECollection OverV .pptx
VTUOOPMCA5THMODULECollection OverV .pptx
VeenaNaik23
 
mca5thCollection OverViCollection O.pptx
mca5thCollection OverViCollection O.pptxmca5thCollection OverViCollection O.pptx
mca5thCollection OverViCollection O.pptx
VeenaNaik23
 
VTUOOPMCA5THMODULECollection OverVi.pptx
VTUOOPMCA5THMODULECollection OverVi.pptxVTUOOPMCA5THMODULECollection OverVi.pptx
VTUOOPMCA5THMODULECollection OverVi.pptx
VeenaNaik23
 
VTUOOPMCA5THMODULEvCollection OverV.pptx
VTUOOPMCA5THMODULEvCollection OverV.pptxVTUOOPMCA5THMODULEvCollection OverV.pptx
VTUOOPMCA5THMODULEvCollection OverV.pptx
VeenaNaik23
 
Java Collections
Java CollectionsJava Collections
Java Collections
parag
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
rangariprajwal4554
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
Java collections
Java collectionsJava collections
Java collections
padmad2291
 
Ad

More from SAGARDAVE29 (12)

Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
SAGARDAVE29
 
Exception Handling
Exception HandlingException Handling
Exception Handling
SAGARDAVE29
 
JAVA Multithreading
JAVA MultithreadingJAVA Multithreading
JAVA Multithreading
SAGARDAVE29
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
SAGARDAVE29
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
SAGARDAVE29
 
Exception handling
Exception handlingException handling
Exception handling
SAGARDAVE29
 
More oop in java
More oop in javaMore oop in java
More oop in java
SAGARDAVE29
 
Coding Style & Tips for JAVA
Coding Style & Tips for JAVACoding Style & Tips for JAVA
Coding Style & Tips for JAVA
SAGARDAVE29
 
Some Important Methods in JAVA
Some Important Methods in JAVASome Important Methods in JAVA
Some Important Methods in JAVA
SAGARDAVE29
 
Recursion
RecursionRecursion
Recursion
SAGARDAVE29
 
Inheritance & Polymorphism
Inheritance & PolymorphismInheritance & Polymorphism
Inheritance & Polymorphism
SAGARDAVE29
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
SAGARDAVE29
 
Exception Handling
Exception HandlingException Handling
Exception Handling
SAGARDAVE29
 
JAVA Multithreading
JAVA MultithreadingJAVA Multithreading
JAVA Multithreading
SAGARDAVE29
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Exception handling
Exception handlingException handling
Exception handling
SAGARDAVE29
 
More oop in java
More oop in javaMore oop in java
More oop in java
SAGARDAVE29
 
Coding Style & Tips for JAVA
Coding Style & Tips for JAVACoding Style & Tips for JAVA
Coding Style & Tips for JAVA
SAGARDAVE29
 
Some Important Methods in JAVA
Some Important Methods in JAVASome Important Methods in JAVA
Some Important Methods in JAVA
SAGARDAVE29
 
Inheritance & Polymorphism
Inheritance & PolymorphismInheritance & Polymorphism
Inheritance & Polymorphism
SAGARDAVE29
 
Ad

Recently uploaded (20)

Unit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its typesUnit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its types
bharath321164
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Open Access: Revamping Library Learning Resources.
Open Access: Revamping Library Learning Resources.Open Access: Revamping Library Learning Resources.
Open Access: Revamping Library Learning Resources.
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its typesUnit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its types
bharath321164
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 

ArrayList in JAVA

  • 2. ArrayList Class • The java.util.ArrayList class provides resizable array and implements the List interface. Some important points about ArrayList:  It implements all optional list operations & it also permits all elements includes null.  It provides method to manipulate the size of the array that is used internally to store the list.  The constant factor is low compared to that for the LinkedList implementation.
  • 4. JAVA ArrayList • The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified. • If you want to add or remove elements to/from an array, you have to create a new one. While elements can be added and removed from an ArrayList whenever you want. • The syntax is also slightly different: Create an ArrayList object called cars that will store strings: ArrayList<String> cars = new ArrayList<String>(); // Create an ArrayList object
  • 5. Example • The ArrayList class has many useful methods. • In this example , use the add() method to add elements to the ArrayList:
  • 6. Examples of ArrayList Methods • To access an element in the ArrayList, use the get() method and refer to the index number: cars.get(0); Note: Array indexes start with 0: [0] is the first element.[1] is the second element, etc. • To modify an element, use the set() method and refer to the index number: cars.set(0, "Opel"); • To remove an element, use the remove() method and refer to the index number: cars.remove(0); • To remove all the elements in the ArrayList, use the clear() method: cars.clear(); • To find out how many elements an ArrayList have, use the size method: cars.size();