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

More Related Content

What's hot

Java Chapter 05 - Conditions & Loops: part 7
Java Chapter 05 - Conditions & Loops: part 7Java Chapter 05 - Conditions & Loops: part 7
Java Chapter 05 - Conditions & Loops: part 7
DanWooster1
 
Array
ArrayArray
Quick dive to pandas
Quick dive to pandasQuick dive to pandas
Quick dive to pandas
Robin Kiplangat
 
Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapterKrazy Koder
 
Javascript - Arrays - mutator functions
Javascript  - Arrays - mutator functionsJavascript  - Arrays - mutator functions
Javascript - Arrays - mutator functions
Samuel Santos
 
Encapsulation in java | ehsanullah
Encapsulation in java | ehsanullahEncapsulation in java | ehsanullah
Encapsulation in java | ehsanullah
Ehsan Ullah
 
Data structures and algorithms arrays
Data structures and algorithms   arraysData structures and algorithms   arrays
Data structures and algorithms arrays
chauhankapil
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in Scala
Ayush Mishra
 
Standard template library
Standard template libraryStandard template library
Standard template library
ThamizhselviKrishnam
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
DADITIRUMALATARUN
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
abdullah619
 
Ts project Hash based inventory system
Ts project Hash based inventory systemTs project Hash based inventory system
Ts project Hash based inventory system
DADITIRUMALATARUN
 
C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
MohitKumar1985
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
Abdul Rahman Sherzad
 
Design and analysis of algorithm
Design and analysis of algorithmDesign and analysis of algorithm
Design and analysis of algorithm
laibaNoor60
 
Javascript - Arrays - accessor functions
Javascript   - Arrays - accessor functionsJavascript   - Arrays - accessor functions
Javascript - Arrays - accessor functions
Samuel Santos
 
Javascript ADT - List
Javascript   ADT - ListJavascript   ADT - List
Javascript ADT - List
Samuel Santos
 
Intro++ to C#
Intro++ to C#Intro++ to C#
Excel data from matlab
Excel data from matlabExcel data from matlab
Excel data from matlab
coursesub
 
Integer sequence
Integer sequenceInteger sequence
Integer sequence
INA SINGHAL
 

What's hot (20)

Java Chapter 05 - Conditions & Loops: part 7
Java Chapter 05 - Conditions & Loops: part 7Java Chapter 05 - Conditions & Loops: part 7
Java Chapter 05 - Conditions & Loops: part 7
 
Array
ArrayArray
Array
 
Quick dive to pandas
Quick dive to pandasQuick dive to pandas
Quick dive to pandas
 
Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapter
 
Javascript - Arrays - mutator functions
Javascript  - Arrays - mutator functionsJavascript  - Arrays - mutator functions
Javascript - Arrays - mutator functions
 
Encapsulation in java | ehsanullah
Encapsulation in java | ehsanullahEncapsulation in java | ehsanullah
Encapsulation in java | ehsanullah
 
Data structures and algorithms arrays
Data structures and algorithms   arraysData structures and algorithms   arrays
Data structures and algorithms arrays
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in Scala
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Ts project Hash based inventory system
Ts project Hash based inventory systemTs project Hash based inventory system
Ts project Hash based inventory system
 
C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
Design and analysis of algorithm
Design and analysis of algorithmDesign and analysis of algorithm
Design and analysis of algorithm
 
Javascript - Arrays - accessor functions
Javascript   - Arrays - accessor functionsJavascript   - Arrays - accessor functions
Javascript - Arrays - accessor functions
 
Javascript ADT - List
Javascript   ADT - ListJavascript   ADT - List
Javascript ADT - List
 
Intro++ to C#
Intro++ to C#Intro++ to C#
Intro++ to C#
 
Excel data from matlab
Excel data from matlabExcel data from matlab
Excel data from matlab
 
Integer sequence
Integer sequenceInteger sequence
Integer sequence
 

Similar to ArrayList in JAVA

Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
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
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
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)
SURBHI SAROHA
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
Java collections
Java collectionsJava collections
Java collectionspadmad2291
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
TOPS Technologies
 
Collection framework
Collection frameworkCollection framework
Collection framework
BindhuBhargaviTalasi
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
Ravi Chythanya
 
Java Collections
Java  Collections Java  Collections

Similar to ArrayList in JAVA (20)

Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
arraylistinjava.pptx
arraylistinjava.pptxarraylistinjava.pptx
arraylistinjava.pptx
 
Java util
Java utilJava util
Java util
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Collections
CollectionsCollections
Collections
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Java collections
Java collectionsJava collections
Java collections
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 
Java Collections
Java  Collections Java  Collections
Java Collections
 

More from SAGARDAVE29

Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
SAGARDAVE29
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
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
 
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
 

More from SAGARDAVE29 (12)

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

Recently uploaded

Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 

Recently uploaded (20)

Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 

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();