SlideShare a Scribd company logo
1 of 6
ARRAYLIST
Arraylist class
The java.util.ArrayList class provides resizable array and implements the List interface.
Some important points about ArrayList:
 It is grownable.
 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 Linked List implementation.
 JAVAArrayList 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.
Methods in Arraylist
Add( ) inserts the element to the arraylist
addAll( ) adds all elements of a collection to arraylist
clear( ) removes all the elements from arraylist
removeAll( ) removes multiple elements from the arraylist
Remove( ) removes the single element from the arraylist
size( ) returns the length of an arraylist
contains( ) checks if the element is present in the arraylist
containsAll( ) checks if a collection is a subset of arraylist
retainAll( ) retains only the common elements
Example
The ArrayList class has many useful methods.
In this example, I use the add() method to add elements to the ArrayList.
import java.util.ArrayList;
public class MyClass {
public static void main(String[] args) {
ArrayList<String> cars =new ArrayList<String>();
cars.add("Volve");
cars.add(“BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars):
}
}
Examples of Arraylist Methods
To access an element in the ArrayList, use the get() method 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

Similar to arraylistinjava.pptx

I really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdfI really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdf
dbrienmhompsonkath75
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
phanleson
 
COLLECTIONS.pptx
COLLECTIONS.pptxCOLLECTIONS.pptx
COLLECTIONS.pptx
SruthyPJ
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 

Similar to arraylistinjava.pptx (20)

Presentation1
Presentation1Presentation1
Presentation1
 
Java collections
Java collectionsJava collections
Java collections
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java.util
Java.utilJava.util
Java.util
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
I really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdfI really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdf
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Collections
CollectionsCollections
Collections
 
COLLECTIONS.pptx
COLLECTIONS.pptxCOLLECTIONS.pptx
COLLECTIONS.pptx
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
Array list
Array listArray list
Array list
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 

Recently uploaded

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 

arraylistinjava.pptx

  • 2. Arraylist class The java.util.ArrayList class provides resizable array and implements the List interface. Some important points about ArrayList:  It is grownable.  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 Linked List implementation.  JAVAArrayList 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.
  • 3. Methods in Arraylist Add( ) inserts the element to the arraylist addAll( ) adds all elements of a collection to arraylist clear( ) removes all the elements from arraylist removeAll( ) removes multiple elements from the arraylist Remove( ) removes the single element from the arraylist size( ) returns the length of an arraylist contains( ) checks if the element is present in the arraylist containsAll( ) checks if a collection is a subset of arraylist retainAll( ) retains only the common elements
  • 4. Example The ArrayList class has many useful methods. In this example, I use the add() method to add elements to the ArrayList. import java.util.ArrayList; public class MyClass { public static void main(String[] args) { ArrayList<String> cars =new ArrayList<String>(); cars.add("Volve"); cars.add(“BMW"); cars.add("Ford"); cars.add("Mazda"); System.out.println(cars): } }
  • 5. Examples of Arraylist Methods To access an element in the ArrayList, use the get() method 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();