SlideShare une entreprise Scribd logo
1  sur  12
Programming in Java
Topic: ArrayList
Introduction
• Standard Java arrays are of a fixed length.
• After arrays are created, they cannot grow or shrink, which
means we can not resize Arrays.
• Arrays are useful when we know in advance how many
elements the array is to hold.
• ArrayList is a collection which provides the implementation of
resizable array.
ArrayList
• The ArrayList class extends AbstractList and implements the List
interface.
• Defined in java.util package.
• ArrayList supports dynamic arrays that can grow as needed.
• Array lists are created with an initial size.
• When this size is exceeded, the collection is automatically enlarged.
• When objects are removed, the array may be shrunk.
ArrayList Constructors
• T he ArrayList class supports three constructors.
 ArrayList() : creates an empty array list with an initial capacity
sufficient to hold 10 elements.
 ArrayList(int capacity) : creates an array list that has the
specified initial capacity.
 ArrayList(Collection c) : creates an array list that is initialized
with the elements of the collection c.
Methods of ArrayList
boolean add(Object o)
• Appends the specified element to the end of this list.
void add(int index, Object element)
• Inserts the specified element at the specified position index in
this list.
• Throws IndexOutOfBoundsException if the specified index is
out of range.
boolean addAll(Collection c )
• Appends all of the elements in the specified collection to the end of
this list.
• Throws NullPointerException if the specified collection is null.
boolean addAll(int index, Collection c )
• Inserts all of the elements of the specified collection into this list,
starting at the specified position.
• Throws NullPointerException if the specified collection is null.
void clear()
• Removes all of the elements from this list.
Object remove(int index)
• Removes the element at the specified position in this list.
boolean remove(Object o)
• Removes the first specified object present in the arraylist.
int size()
• Returns the number of elements in the list.
boolean contains(Object o)
• Returns true if this list contains the specified element.
Object get(int index)
• Returns the element at the specified position in this list.
int indexOf(Object o)
• Returns the index in this list of the first occurrence of the
specified element, or -1 if the List does not contain the element.
int lastIndexOf(Object o)
• Returns the index in this list of the last occurrence of the
specified element, or -1.
void ensureCapacity(int minCapacity)
• Increases the capacity of this ArrayList instance, if necessary,
to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
Object set(int index, Object element)
• Replaces the element at the specified position in this list with
the specified element.
• Throws IndexOutOfBoundsException if the specified index is
out of range (index < 0 || index >= size()).
boolean isEmpty()
• used to check whether the Arraylist is empty or not?
void trimToSize()
• reduces the size of an arraylist to the number of elements
present in the arraylist.
• import java.util.*;
• class TestCollection2
• {
• public static void main(String args[])
• {
• ArrayList<String> al=new ArrayList<String>();
• al.add("Ravi");
• al.add("Vijay");
• al.add("Ravi");
• al.add("Ajay");
• for(String obj:al)
• System.out.println(obj);
• }
• }
A2003822018_21789_17_2018_09. ArrayList.ppt

Contenu connexe

Similaire à A2003822018_21789_17_2018_09. ArrayList.ppt

java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
adinathassociates
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
Krishna Sujeer
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 

Similaire à A2003822018_21789_17_2018_09. ArrayList.ppt (20)

collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
 
Java collections
Java collectionsJava collections
Java collections
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
I need to implement the following ArrayList methods in javapublic.pdf
I need to implement the  following ArrayList methods in javapublic.pdfI need to implement the  following ArrayList methods in javapublic.pdf
I need to implement the following ArrayList methods in javapublic.pdf
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
List classes
List classesList classes
List classes
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Array properties
Array propertiesArray properties
Array properties
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
Java.util
Java.utilJava.util
Java.util
 
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
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 

Plus de RithwikRanjan

Plus de RithwikRanjan (13)

A1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.pptA1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.ppt
 
INTERNSHIP PRESENTATION.pptx
INTERNSHIP PRESENTATION.pptxINTERNSHIP PRESENTATION.pptx
INTERNSHIP PRESENTATION.pptx
 
internship.pptx
internship.pptxinternship.pptx
internship.pptx
 
AM.pptx
AM.pptxAM.pptx
AM.pptx
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
sam_technical_seminar.pptx
sam_technical_seminar.pptxsam_technical_seminar.pptx
sam_technical_seminar.pptx
 
sam_report.pptx
sam_report.pptxsam_report.pptx
sam_report.pptx
 
TQM-Module 5.pptx
TQM-Module 5.pptxTQM-Module 5.pptx
TQM-Module 5.pptx
 
CIM MODULE 2.pptx
CIM MODULE 2.pptxCIM MODULE 2.pptx
CIM MODULE 2.pptx
 
0_A1590026209_21789_20_2018_0 Lecture.ppt
0_A1590026209_21789_20_2018_0 Lecture.ppt0_A1590026209_21789_20_2018_0 Lecture.ppt
0_A1590026209_21789_20_2018_0 Lecture.ppt
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
 
A1869984431_21789_28_2018_Abstract Class.ppt
A1869984431_21789_28_2018_Abstract Class.pptA1869984431_21789_28_2018_Abstract Class.ppt
A1869984431_21789_28_2018_Abstract Class.ppt
 

Dernier

Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...
Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...
Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...
rajveermohali2022
 
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
rajveermohali2022
 
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
rajveerescorts2022
 
Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Nitya salvi
 
Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...
Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...
Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...
minkseocompany
 
2024_Rupantara Jogare Namajapa II Nishitharanjan
2024_Rupantara Jogare Namajapa II Nishitharanjan2024_Rupantara Jogare Namajapa II Nishitharanjan
2024_Rupantara Jogare Namajapa II Nishitharanjan
Nishitharanjan Rout
 

Dernier (20)

gatiin-namaa-meeqa .pdf
gatiin-namaa-meeqa                        .pdfgatiin-namaa-meeqa                        .pdf
gatiin-namaa-meeqa .pdf
 
📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls
 
Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...
Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...
Chandigarh Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escor...
 
Style Victorious Cute Outfits for Winners
Style Victorious Cute Outfits for WinnersStyle Victorious Cute Outfits for Winners
Style Victorious Cute Outfits for Winners
 
Call Girls In Jamnagar Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enj...
Call Girls In Jamnagar Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enj...Call Girls In Jamnagar Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enj...
Call Girls In Jamnagar Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enj...
 
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
 
Call Girls In Mumbai Just Genuine Call ☎ 7738596112✅ Call Girl Andheri East P...
Call Girls In Mumbai Just Genuine Call ☎ 7738596112✅ Call Girl Andheri East P...Call Girls In Mumbai Just Genuine Call ☎ 7738596112✅ Call Girl Andheri East P...
Call Girls In Mumbai Just Genuine Call ☎ 7738596112✅ Call Girl Andheri East P...
 
Tinted Sunscreen For Soft and Smooth Skin
Tinted Sunscreen For Soft and Smooth SkinTinted Sunscreen For Soft and Smooth Skin
Tinted Sunscreen For Soft and Smooth Skin
 
"Paltr Packaging: Streamlined Order Process for Seamless Deliveries"
"Paltr Packaging: Streamlined Order Process for Seamless Deliveries""Paltr Packaging: Streamlined Order Process for Seamless Deliveries"
"Paltr Packaging: Streamlined Order Process for Seamless Deliveries"
 
UNIVERSAL HUMAN VALUES -Harmony in the Human Being
UNIVERSAL HUMAN VALUES -Harmony in the Human BeingUNIVERSAL HUMAN VALUES -Harmony in the Human Being
UNIVERSAL HUMAN VALUES -Harmony in the Human Being
 
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
 
Escorts Service Model Basti 👉 Just CALL ME: 8617697112 💋 Call Out Call Both W...
Escorts Service Model Basti 👉 Just CALL ME: 8617697112 💋 Call Out Call Both W...Escorts Service Model Basti 👉 Just CALL ME: 8617697112 💋 Call Out Call Both W...
Escorts Service Model Basti 👉 Just CALL ME: 8617697112 💋 Call Out Call Both W...
 
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
 
Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Raigad Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
 
Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...
Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...
Top 20: Best & Hottest Russian Pornstars Right Now (2024) Russian Porn Stars ...
 
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
 
Ladies kitty party invitation messages and greetings.pdf
Ladies kitty party invitation messages and greetings.pdfLadies kitty party invitation messages and greetings.pdf
Ladies kitty party invitation messages and greetings.pdf
 
The Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue ZonesThe Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue Zones
 
2024_Rupantara Jogare Namajapa II Nishitharanjan
2024_Rupantara Jogare Namajapa II Nishitharanjan2024_Rupantara Jogare Namajapa II Nishitharanjan
2024_Rupantara Jogare Namajapa II Nishitharanjan
 
Yamunanagar Escorts Service Girl ^ 9332606886, WhatsApp Anytime Yamunanagar
Yamunanagar Escorts Service Girl ^ 9332606886, WhatsApp Anytime YamunanagarYamunanagar Escorts Service Girl ^ 9332606886, WhatsApp Anytime Yamunanagar
Yamunanagar Escorts Service Girl ^ 9332606886, WhatsApp Anytime Yamunanagar
 

A2003822018_21789_17_2018_09. ArrayList.ppt

  • 2. Introduction • Standard Java arrays are of a fixed length. • After arrays are created, they cannot grow or shrink, which means we can not resize Arrays. • Arrays are useful when we know in advance how many elements the array is to hold. • ArrayList is a collection which provides the implementation of resizable array.
  • 3. ArrayList • The ArrayList class extends AbstractList and implements the List interface. • Defined in java.util package. • ArrayList supports dynamic arrays that can grow as needed. • Array lists are created with an initial size. • When this size is exceeded, the collection is automatically enlarged. • When objects are removed, the array may be shrunk.
  • 4. ArrayList Constructors • T he ArrayList class supports three constructors.  ArrayList() : creates an empty array list with an initial capacity sufficient to hold 10 elements.  ArrayList(int capacity) : creates an array list that has the specified initial capacity.  ArrayList(Collection c) : creates an array list that is initialized with the elements of the collection c.
  • 5. Methods of ArrayList boolean add(Object o) • Appends the specified element to the end of this list. void add(int index, Object element) • Inserts the specified element at the specified position index in this list. • Throws IndexOutOfBoundsException if the specified index is out of range.
  • 6. boolean addAll(Collection c ) • Appends all of the elements in the specified collection to the end of this list. • Throws NullPointerException if the specified collection is null. boolean addAll(int index, Collection c ) • Inserts all of the elements of the specified collection into this list, starting at the specified position. • Throws NullPointerException if the specified collection is null.
  • 7. void clear() • Removes all of the elements from this list. Object remove(int index) • Removes the element at the specified position in this list. boolean remove(Object o) • Removes the first specified object present in the arraylist. int size() • Returns the number of elements in the list.
  • 8. boolean contains(Object o) • Returns true if this list contains the specified element. Object get(int index) • Returns the element at the specified position in this list. int indexOf(Object o) • Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain the element. int lastIndexOf(Object o) • Returns the index in this list of the last occurrence of the specified element, or -1.
  • 9. void ensureCapacity(int minCapacity) • Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. Object set(int index, Object element) • Replaces the element at the specified position in this list with the specified element. • Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
  • 10. boolean isEmpty() • used to check whether the Arraylist is empty or not? void trimToSize() • reduces the size of an arraylist to the number of elements present in the arraylist.
  • 11. • import java.util.*; • class TestCollection2 • { • public static void main(String args[]) • { • ArrayList<String> al=new ArrayList<String>(); • al.add("Ravi"); • al.add("Vijay"); • al.add("Ravi"); • al.add("Ajay"); • for(String obj:al) • System.out.println(obj); • } • }

Notes de l'éditeur

  1. TestArrayList.java, TestCollection1.java