SlideShare a Scribd company logo
6
Most read
9
Most read
10
Most read
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
01 Collections Framework
02 Hierarchy of ArrayList Class
03 ArrayList in Java
04 Internal Working of ArrayList
05 Constructors of ArrayList
06 Methods of ArrayList
07 Benefits of ArrayList vs Arrays
Topics For Today’s Discussion
Collections Framework
Collection
SortedSet
SetList
Priority Queue
ArrayDeque
TreeSet
LinkedHashSet
HashSet
Iterable
Queue
ArrayList
LinkedList
Vector
Stack
Deque
ArrayList
Collection
List
Abstract List
Hierarchy of Array List Class
Iterable
extends
implements
extends
extends
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
ArrayList in Java
ArrayList is a part of collection framework present in java.util package. It provides dynamic arrays in Java.
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Internal Working of ArrayList
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
Array List Initialization
Adding elements to Array List
Capacity of Array List is Full
Creating a new array & moving the
elements to new array
Size is increased to double
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Constructors of ArrayList
ArrayList(int Capacity)
ArrayList(Collection c)
ArrayList( )
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Constructors of ArrayList
ArrayList(int Capacity)
ArrayList(Collection c)
ArrayList( ) This constructor builds an empty array list.
Syntax:
ArrayList<E> myArray = new ArrayList<E>();
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Constructors of ArrayList
ArrayList(int Capacity)
ArrayList( )
ArrayList(Collection c)
This constructor builds an array list that is initialized with the
elements of the collection c.
public boolean addAll(Collection c)
Syntax:
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Constructors of ArrayList
ArrayList(Collection c)
ArrayList( )
ArrayList(int Capacity)
It is used to build an array list that has the specified initial capacity.
ArrayList myArray = new ArrayList(int
initialCapacity);
Syntax:
Methods of Arraylist
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
This method is used to insert a specific element at a specific position
index in a list.
ArrayList<String> al=new ArrayList<String>();
al.add(“Jino");
al.add(“Piyush");
al.add(“Pramod");
Example:
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
This method is used to remove all the elements from any list.
ArrayList<String> al=new ArrayList<String>();
al.add("abc");
al.add("xyz");
System.out.println("ArrayList before clear: "+al);
al.clear();
System.out.println("ArrayList after clear: "+al);
Example:
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
ArrayList<Integer> al = new ArrayList<Integer>(9);
al.add(2);
al.add(4);
al.add(5);
al.trimToSize();
System.out.println("The List elements are:");
The trimToSize() method in Java trims the capacity of an ArrayList instance
to be the list’s current size. This method is used to trim an ArrayList
instance to the number of elements it contains.
Example:
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
ArrayList<Integer> al = new ArrayList<Integer>(9);
al.add(2);
al.add(4);
al.add(5);
int pos = al. indexOf(3);
This method returns the index of the first occurrence of the specified
element in this list, or -1 if this list does not contain the element.
Example:
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
ArrayList<String> al=new ArrayList<String>();
Object cloneList; //Added 2 elements
al.add("abc");
al.add("xyz");
System.out.println("Elements are: ");
cloneList = al.clone();
System.out.println("Elements in cloneList are:");
Returns a shallow copy of this ArrayList.
Example:
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
arrayList.add("element_1");
arrayList.add("element_2");
arrayList.add("element_3");
arrayList.add("element_4");
Object[] objArray = arrayList.toArray();
Returns an array containing all of the elements in this list in the correct
order; the runtime type of the returned array is that of the specified
array.
Example:
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
arrayList.add(“J");
arrayList.add(“I");
arrayList.add(“N");
arrayList.add(“O");
arraylist.remove(“N”);
Example:
java.util.ArrayList.remove(Object) method removes the first occurrence
of the specified element from this list, if it is present. If the list does not
contain the element, it is unchanged.
void add(int index, Object element)
void clear( )
void trimToSize()
Int indexOf(Object O)
Object clone()
Object[] to Array()
Object remove(int index)
Int size()
Declaration: public int size()
arrayList.add(“J");
arrayList.add(“I");
arrayList.add(“N");
arrayList.add(“O");
int asize = arraylist.size();
It returns the number of elements in this list i.e the size of the list.
Example:
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Advantages of ArrayList Over Array
Allows to add duplicate elements
Can traverse in both directions
Insert & Remove elements at particular
position
ArrayList is Variable length
Size can be modified dynamically
Can add any type of data in arraylist
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka

More Related Content

PPTX
Java - Collections framework
Riccardo Cardin
 
PPT
9. Input Output in java
Nilesh Dalvi
 
PPSX
Collections - Maps
Hitesh-Java
 
PPS
Wrapper class
kamal kotecha
 
PPT
Exception handling in java
Pratik Soares
 
PPTX
Exception handling
PhD Research Scholar
 
PPTX
Strings in Java
Abhilash Nair
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
Java - Collections framework
Riccardo Cardin
 
9. Input Output in java
Nilesh Dalvi
 
Collections - Maps
Hitesh-Java
 
Wrapper class
kamal kotecha
 
Exception handling in java
Pratik Soares
 
Exception handling
PhD Research Scholar
 
Strings in Java
Abhilash Nair
 

What's hot (20)

PDF
Java I/o streams
Hamid Ghorbani
 
PDF
Java Arrays
OXUS 20
 
PPT
Collection Framework in java
CPD INDIA
 
PPT
Java static keyword
Lovely Professional University
 
PPT
Java collection
Arati Gadgil
 
PPS
Java Exception handling
kamal kotecha
 
PPT
JAVA OOP
Sunil OS
 
PPT
Java collections concept
kumar gaurav
 
PDF
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Edureka!
 
PDF
Java Linked List Tutorial | Edureka
Edureka!
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PDF
07 java collection
Abhishek Khune
 
PPS
String and string buffer
kamal kotecha
 
PDF
Arrays in Java
Naz Abdalla
 
PDF
Collections In Java
Binoj T E
 
PPTX
ArrayList in JAVA
SAGARDAVE29
 
PPTX
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
PPTX
Arrays in java
Arzath Areeff
 
PDF
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Edureka!
 
PPTX
Java Final Keyword
Ducat India
 
Java I/o streams
Hamid Ghorbani
 
Java Arrays
OXUS 20
 
Collection Framework in java
CPD INDIA
 
Java static keyword
Lovely Professional University
 
Java collection
Arati Gadgil
 
Java Exception handling
kamal kotecha
 
JAVA OOP
Sunil OS
 
Java collections concept
kumar gaurav
 
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Edureka!
 
Java Linked List Tutorial | Edureka
Edureka!
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
07 java collection
Abhishek Khune
 
String and string buffer
kamal kotecha
 
Arrays in Java
Naz Abdalla
 
Collections In Java
Binoj T E
 
ArrayList in JAVA
SAGARDAVE29
 
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
Arrays in java
Arzath Areeff
 
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Edureka!
 
Java Final Keyword
Ducat India
 
Ad

Similar to Java ArrayList Tutorial | Edureka (20)

PPT
A2003822018_21789_17_2018_09. ArrayList.ppt
RithwikRanjan
 
PPT
L11 array list
teach4uin
 
PPTX
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
PPTX
collection framework.pptx
SoniaKapoor56
 
PPTX
arraylistinjava.pptx
dintakurthigayathri9
 
PPTX
ArrayList class and useful methods.pptx
Abid523408
 
PDF
Array list (java platform se 8 )
charan kumar
 
PDF
For this lab you will complete the class MyArrayList by implementing.pdf
fashiongallery1
 
PDF
Everything needs to be according to the instructions- thank you! SUPPO.pdf
firstchoiceajmer
 
PPTX
Java ArrayList Video Tutorial
Marcus Biel
 
PPTX
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
DOCX
ArrayList.docx
veerendranath12
 
DOC
Advanced core java
Rajeev Uppala
 
PDF
Lecture 8_٠٨٣٣٣٦taiz unvercity object oreinted programming.pdf
nabeehmohammedtaher
 
DOCX
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
davidwarner122
 
PPT
12_-_Collections_Framework
Krishna Sujeer
 
PPTX
Collections lecture 35 40
bhawna sharma
 
PPTX
Lecture 9
talha ijaz
 
PPTX
Collection Framework-1.pptx
SarthakSrivastava70
 
PPTX
Collections - Lists & sets
RatnaJava
 
A2003822018_21789_17_2018_09. ArrayList.ppt
RithwikRanjan
 
L11 array list
teach4uin
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
collection framework.pptx
SoniaKapoor56
 
arraylistinjava.pptx
dintakurthigayathri9
 
ArrayList class and useful methods.pptx
Abid523408
 
Array list (java platform se 8 )
charan kumar
 
For this lab you will complete the class MyArrayList by implementing.pdf
fashiongallery1
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
firstchoiceajmer
 
Java ArrayList Video Tutorial
Marcus Biel
 
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
ArrayList.docx
veerendranath12
 
Advanced core java
Rajeev Uppala
 
Lecture 8_٠٨٣٣٣٦taiz unvercity object oreinted programming.pdf
nabeehmohammedtaher
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
davidwarner122
 
12_-_Collections_Framework
Krishna Sujeer
 
Collections lecture 35 40
bhawna sharma
 
Lecture 9
talha ijaz
 
Collection Framework-1.pptx
SarthakSrivastava70
 
Collections - Lists & sets
RatnaJava
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 

Recently uploaded (20)

PDF
Architecture of the Future (09152021)
EdwardMeyman
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Software Development Methodologies in 2025
KodekX
 
Architecture of the Future (09152021)
EdwardMeyman
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
This slide provides an overview Technology
mineshkharadi333
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Software Development Methodologies in 2025
KodekX
 

Java ArrayList Tutorial | Edureka

  • 1. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
  • 2. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 01 Collections Framework 02 Hierarchy of ArrayList Class 03 ArrayList in Java 04 Internal Working of ArrayList 05 Constructors of ArrayList 06 Methods of ArrayList 07 Benefits of ArrayList vs Arrays Topics For Today’s Discussion
  • 5. ArrayList Collection List Abstract List Hierarchy of Array List Class Iterable extends implements extends extends
  • 6. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training ArrayList in Java ArrayList is a part of collection framework present in java.util package. It provides dynamic arrays in Java.
  • 7. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Internal Working of ArrayList myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] Array List Initialization Adding elements to Array List Capacity of Array List is Full Creating a new array & moving the elements to new array Size is increased to double
  • 8. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Constructors of ArrayList ArrayList(int Capacity) ArrayList(Collection c) ArrayList( )
  • 9. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Constructors of ArrayList ArrayList(int Capacity) ArrayList(Collection c) ArrayList( ) This constructor builds an empty array list. Syntax: ArrayList<E> myArray = new ArrayList<E>();
  • 10. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Constructors of ArrayList ArrayList(int Capacity) ArrayList( ) ArrayList(Collection c) This constructor builds an array list that is initialized with the elements of the collection c. public boolean addAll(Collection c) Syntax:
  • 11. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Constructors of ArrayList ArrayList(Collection c) ArrayList( ) ArrayList(int Capacity) It is used to build an array list that has the specified initial capacity. ArrayList myArray = new ArrayList(int initialCapacity); Syntax:
  • 13. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() This method is used to insert a specific element at a specific position index in a list. ArrayList<String> al=new ArrayList<String>(); al.add(“Jino"); al.add(“Piyush"); al.add(“Pramod"); Example:
  • 14. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() This method is used to remove all the elements from any list. ArrayList<String> al=new ArrayList<String>(); al.add("abc"); al.add("xyz"); System.out.println("ArrayList before clear: "+al); al.clear(); System.out.println("ArrayList after clear: "+al); Example:
  • 15. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() ArrayList<Integer> al = new ArrayList<Integer>(9); al.add(2); al.add(4); al.add(5); al.trimToSize(); System.out.println("The List elements are:"); The trimToSize() method in Java trims the capacity of an ArrayList instance to be the list’s current size. This method is used to trim an ArrayList instance to the number of elements it contains. Example:
  • 16. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() ArrayList<Integer> al = new ArrayList<Integer>(9); al.add(2); al.add(4); al.add(5); int pos = al. indexOf(3); This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. Example:
  • 17. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() ArrayList<String> al=new ArrayList<String>(); Object cloneList; //Added 2 elements al.add("abc"); al.add("xyz"); System.out.println("Elements are: "); cloneList = al.clone(); System.out.println("Elements in cloneList are:"); Returns a shallow copy of this ArrayList. Example:
  • 18. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() arrayList.add("element_1"); arrayList.add("element_2"); arrayList.add("element_3"); arrayList.add("element_4"); Object[] objArray = arrayList.toArray(); Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array. Example:
  • 19. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() arrayList.add(“J"); arrayList.add(“I"); arrayList.add(“N"); arrayList.add(“O"); arraylist.remove(“N”); Example: java.util.ArrayList.remove(Object) method removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged.
  • 20. void add(int index, Object element) void clear( ) void trimToSize() Int indexOf(Object O) Object clone() Object[] to Array() Object remove(int index) Int size() Declaration: public int size() arrayList.add(“J"); arrayList.add(“I"); arrayList.add(“N"); arrayList.add(“O"); int asize = arraylist.size(); It returns the number of elements in this list i.e the size of the list. Example:
  • 21. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Advantages of ArrayList Over Array Allows to add duplicate elements Can traverse in both directions Insert & Remove elements at particular position ArrayList is Variable length Size can be modified dynamically Can add any type of data in arraylist