SlideShare a Scribd company logo
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.
Most read
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:
Most read
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.
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

What's hot (20)

Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
Hitesh-Java
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
Intro C# Book
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
spin_naresh
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
KrutikaWankhade1
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
Raghuveer Guthikonda
 
Php array
Php arrayPhp array
Php array
Nikul Shah
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
Shalabh Chaudhary
 
Java arrays
Java arraysJava arrays
Java arrays
Jin Castor
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
Hitesh-Java
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
Intro C# Book
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
KrutikaWankhade1
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 

Similar to Java ArrayList Tutorial | Edureka (20)

Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Collection Framework.power point presentation.......
Collection Framework.power point presentation.......Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdfJava R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
kamalabhushanamnokki
 
arraylistinjava.pptx
arraylistinjava.pptxarraylistinjava.pptx
arraylistinjava.pptx
dintakurthigayathri9
 
Presentation1
Presentation1Presentation1
Presentation1
Anand Grewal
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Java collections
Java collectionsJava collections
Java collections
Hamid Ghorbani
 
Collections in object oriented programming
Collections in object oriented programmingCollections in object oriented programming
Collections in object oriented programming
KaranAgrawal78
 
16 containers
16   containers16   containers
16 containers
dhrubo kayal
 
java unit 4 pdf - about java collections
java unit 4 pdf - about java collectionsjava unit 4 pdf - about java collections
java unit 4 pdf - about java collections
aapalaks
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
Dr.EEM(Java Collection Jrameworkaa).pptx
Dr.EEM(Java Collection Jrameworkaa).pptxDr.EEM(Java Collection Jrameworkaa).pptx
Dr.EEM(Java Collection Jrameworkaa).pptx
DrMyatMonKyaw
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
veerendranath12
 
collectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptxcollectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
Janki Shah
 
Array properties
Array propertiesArray properties
Array properties
Shravan Sharma
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
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
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Collection Framework.power point presentation.......
Collection Framework.power point presentation.......Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdfJava R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
kamalabhushanamnokki
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
Collections in object oriented programming
Collections in object oriented programmingCollections in object oriented programming
Collections in object oriented programming
KaranAgrawal78
 
java unit 4 pdf - about java collections
java unit 4 pdf - about java collectionsjava unit 4 pdf - about java collections
java unit 4 pdf - about java collections
aapalaks
 
Dr.EEM(Java Collection Jrameworkaa).pptx
Dr.EEM(Java Collection Jrameworkaa).pptxDr.EEM(Java Collection Jrameworkaa).pptx
Dr.EEM(Java Collection Jrameworkaa).pptx
DrMyatMonKyaw
 
collectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptxcollectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
Janki Shah
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
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
 
Ad

More from Edureka! (20)

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

Recently uploaded (20)

Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 

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