SlideShare a Scribd company logo
1 of 13
Array List:
import java.util.ArrayList;
It allow expandable array dynamically.
 An arraylist automatically expand as data is added.
 Access to any element of an array list is O(1);
 Arraylist has method for inserting ,deleting and updating;
 Arraylist can be traversed using for each loop or indexes.
Syntax:
ArrayList arrylist-name= new ArrayList();
e.g. arry list name fruits.
Import java.util.ArrayList;
Public class fruits
{
Public static void main(String arr[])
{
ArrayList fruits=new ArrayList();
Fruits.add(“apple”);
Fruits.add(“orange”);
Fruits.add(“mango”);
Fruits.add(“lichi”);
System.out.println(fruits.size());
For( int i=0;i<fruits.size();i++)
{
System.out.println(fruits.get(i));
}
}
Methods in arraylist:
Method description
Adding elements a.add(e) Add e to end of arraylist
a.add(i,e) Insert at index i ,shifting element up
as necessary
Replacing elements a.set(I,e) Set the element at index I to e
Getting element E=a.get(i) Return the objects at index i
searching B=a.contains(e) Return true if array list conatin e
Removing a.clear() Remove all elements from arraylist
a.remove(i) Remove elements at index i
a.removeRange(I,j) Remove elements from position I to j
Import java.util.ArrayList;
Class fruits
{
Public static void main(String []arr)
{
ArrayList<Integer> arrayList= new ArrayList<Integer>();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);for(i=0;i<arrayList.size();i++)
{
System.out.println arrayList.get(i).int value());
}
}
Java Iterator:
To generate successive elements from a series we can use java iterator. It is an improvement over
enumeration interface.
 We can iterate only in one direction.
 Iteration can be done only once . if we need to iterate again we should get a new
iterator.
Import java.util.ArrayList;
Import java.util.Iterator;
Class ExampleIterator
{
Public static void main(String arr[])
{
ArrayList animal=new ArrayList();
Animal.add(“Horse”);
Animal.add(“Lion”);
Animal.add(“tiger”);
Iterator ani=animal.iterator();
While(ani.hasNext())
{
String aniob=(String)aniob.next();
System.out.println(aniob);
}
}
}
List iterator:
It allow bidirectional traversal of a list and modification of elements.
Import java.util.*;
Class Iteratordemo
{
Public static void main(String arr[])
{
ArrayList<String> a1=new ArrayList<String>();
A1.add(“alpha”);
A1.add(“beta”);
A1.add(“gamma”);
A1.add(“eta”);
//use of iterator to display the content
Iterator<String>itr=a1.iterator(); //obtain iterator
While(itr.hasNext()) //check for next
System.out.println(itr.next()+” “); // obtain next element
System.out.println(); //print blank line
//use of iterator to remove element
Itr=a1.iterator;
While(itr.hasNext())
{
If(itr.next().equals(“gamma”));
Itr.remove(); //use of iterator for remove
}
//again display after deletion
Itr.a1.iterator();
While(itr.hasNext())
System.out.println(itr.next()+ “ “);
System.out.println();
//now use of listiterator to add gamma back to list
ListIterator<String> litr =a1.listIterator(); //obtain list iterator
While(litr.hasNext())
{
If(litr.next().equals(“beta”));
Litr.add(“gamma”); //add element using list iterator.
}
//content after addition of gamma
Litr=a1.listiterator();
While(litr.hasnext())
System.out.println(litr.next()+” “);
System.out.println();
//use of listiterator to mdify the object being iterated.
String str;
Litr=a1.listIterator();
While(litr.hasnext())
{
Str=litr.next();
If(str.equals(“alpha”);
Litr.set(“A”); //use of iterator to change element
Else if(str.equals(“beta”)
Litr.set(“B”);
}
//use of list iterator to display in backward
While(litr.hasprevious())
{
System.out.println(litr.previous()+” “);// display list in reverse order
}
System.out.println();
}
}
For each Loop:
To make iteration over array convenient we can use for each loop
For(type var:arr)
{
Body of loop;
}
e.g
double []arr={1,2,3,4,5,6,7,8};
int sum=0;
for(double d:arr)
{
Sum +=d;
}
e.g
int arr[]={ 12,13,14,15};
for(int i:arr)
{
System.out.println(i);
}
Scanner class:
To facilitate the user input we can use the java library scanner class. Scanner directly
intract with system input buffer for values.
e.g
import java.util.Scanner;
class Scan
{
Public static void main(String arr[])
{
Scanner s=new Scanner(System.in);
Int a=s.nextInt();
Int b=s.nextInt();
Some methods to be use with scanner class.
nextByte(); will accept byte from input
nextShort(); will accept short
nextLong(); will accept long
nextLine(); accept line of string
nextBoolean(); accept boolean
next float(); accept float
Array:
The similar data type elements, variable or objects can be stored in the array.
Array can store homogenous data type variable.
Array in C/C++ and Java are totally different.
In java array are objects
e.g
int array[]; // here array is set to null there is nothing in the array
if we want to the actual physical array on memory then we have to allocate the memory
with new
so
int array[];
array[]=new int[12];
after this statement is executed arra will refer to array of 12 integer with no value but by default
there is zero values in the array.
Array can also be initialized when they are declared
Like’
Int array[]={12,13,12,13,12,13,12,13,12,13};
Two dimensional array:
Int twoD[][]=new int[4][5];
Class twoD
{
Public static void main(string arr[])
{
Int twoD[][]=new int[4][5];
Int I,j,k=0;
For(i=0;i<4;i++)
For(j=0;j<5;j++)
{
twoD[i][j]=k;
k++;
}
For(i=0;i<4;I++)
{
For(j=0;j<5;j++)
System.out.println(twoD[i][j] +” “);
System.out.println();
}
}
}
e.g find the average ofinteger stored in array
class Avg
{
Public static void main(String arr[])
{
Double num[]={12.2,13.3,14.5,123.5,233.45,23.1};
Double result=0;
Int i=0;
For(i=0;i<5;i++)
Result=result+num[i];
System.out.println(“average=”+result/6);
}
}
}
Irregular array:
Int twoD[][]=new int [4][];
For first element memory is allocated for four element. For second dimensions we can allocate
manually like
twoD[0]= new int[1]
twoD[1]= new int[2]
twoD[2]= new int[3]
twoD[3]= new int[4]
so we can change the memory dynamically for column
class twoD
{
Public static void main(String arr[])
{
Int twoD[][]=ne twoD[0]= new int[1]
twoD[0]= new int[1];
twoD[1]= new int[2];
twoD[2]= new int[3];
twoD[3]=new int[4];
int I,j,k=0;
for(i=0;i<4;i++)
for(j=0;j<i+1;j++)
{
twoD[i][j]=k;
k++;
}
for(i=0;i<4;i++)
for(j=0;j<i+1;j++)
{
System.out.println(twoD[i][j]+” “);
System.out.println();
}
}
}
e.g to find minimum and maximum in an array
code:
int num[]={12,13,11,1,-1,67,89,-90};
int min,max;
min=max=num[0];
for(i=1;i<num.length;i++)
{
If(num[i]<min)
Min=num[i];
If(num[i]>max)
Max=num[i];
}
System.out.println(“minmum and maximum;”+min+” “+max);
}
}
e.g two print the common element in two array
code:
int arr1[]={4,5,6,2,1,3,4};
int arr2[]={12,13,14,15,3,2,4};
for(i=0;i<arr1.length;i++)
for(j=0;j<arr2.length;j++)
{
If(arr1[i]==arr2[j])
{
System.out.println(arr1[i]);
}
}
e.g. program to sort the array
import java.util.Arrays;
class myArray
{
p.s.v.m(String arr[])
{
Int[]myarr={3,2,3,2,3,2,4,5,12,0,-2};
Arrays.sort(myarr);
For(int i=0;i<myarr.length;i++)
{
System.out.println(myarr[i]);
}
}
}

More Related Content

What's hot

Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video TutorialMarcus Biel
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - JavaDrishti Bhalla
 
5 collection framework
5 collection framework5 collection framework
5 collection frameworkMinal Maniar
 
Java collections concept
Java collections conceptJava collections concept
Java collections conceptkumar gaurav
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptxvishal choudhary
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Collections generic
Collections genericCollections generic
Collections genericsandhish
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)Janki Shah
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
collection framework in java
collection framework in javacollection framework in java
collection framework in javaMANOJ KUMAR
 

What's hot (20)

Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video Tutorial
 
07 java collection
07 java collection07 java collection
07 java collection
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Collections generic
Collections genericCollections generic
Collections generic
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
16 containers
16   containers16   containers
16 containers
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 

Similar to Array list

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.pdfdbrienmhompsonkath75
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdfaryan9007
 
import java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfimport java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfanilgoelslg
 
Write a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdfWrite a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdfMALASADHNANI
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfapoorvikamobileworld
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfebrahimbadushata00
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIjagriti srivastava
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 

Similar to Array list (20)

6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.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
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 
import java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfimport java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdf
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Oop lecture7
Oop lecture7Oop lecture7
Oop lecture7
 
Write a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdfWrite a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdf
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdf
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdf
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 

More from vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Recently uploaded

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 

Recently uploaded (20)

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 

Array list

  • 1. Array List: import java.util.ArrayList; It allow expandable array dynamically.  An arraylist automatically expand as data is added.  Access to any element of an array list is O(1);  Arraylist has method for inserting ,deleting and updating;  Arraylist can be traversed using for each loop or indexes. Syntax: ArrayList arrylist-name= new ArrayList(); e.g. arry list name fruits. Import java.util.ArrayList; Public class fruits { Public static void main(String arr[]) { ArrayList fruits=new ArrayList(); Fruits.add(“apple”); Fruits.add(“orange”); Fruits.add(“mango”); Fruits.add(“lichi”); System.out.println(fruits.size()); For( int i=0;i<fruits.size();i++) { System.out.println(fruits.get(i)); }
  • 2. } Methods in arraylist: Method description Adding elements a.add(e) Add e to end of arraylist a.add(i,e) Insert at index i ,shifting element up as necessary Replacing elements a.set(I,e) Set the element at index I to e Getting element E=a.get(i) Return the objects at index i searching B=a.contains(e) Return true if array list conatin e Removing a.clear() Remove all elements from arraylist a.remove(i) Remove elements at index i a.removeRange(I,j) Remove elements from position I to j Import java.util.ArrayList; Class fruits { Public static void main(String []arr) { ArrayList<Integer> arrayList= new ArrayList<Integer>(); arrayList.add(1); arrayList.add(2); arrayList.add(3);for(i=0;i<arrayList.size();i++) { System.out.println arrayList.get(i).int value()); } }
  • 3. Java Iterator: To generate successive elements from a series we can use java iterator. It is an improvement over enumeration interface.  We can iterate only in one direction.  Iteration can be done only once . if we need to iterate again we should get a new iterator. Import java.util.ArrayList; Import java.util.Iterator; Class ExampleIterator { Public static void main(String arr[]) { ArrayList animal=new ArrayList(); Animal.add(“Horse”); Animal.add(“Lion”); Animal.add(“tiger”); Iterator ani=animal.iterator(); While(ani.hasNext()) { String aniob=(String)aniob.next(); System.out.println(aniob); } } }
  • 4. List iterator: It allow bidirectional traversal of a list and modification of elements. Import java.util.*; Class Iteratordemo { Public static void main(String arr[]) { ArrayList<String> a1=new ArrayList<String>(); A1.add(“alpha”); A1.add(“beta”); A1.add(“gamma”); A1.add(“eta”); //use of iterator to display the content Iterator<String>itr=a1.iterator(); //obtain iterator While(itr.hasNext()) //check for next System.out.println(itr.next()+” “); // obtain next element System.out.println(); //print blank line //use of iterator to remove element Itr=a1.iterator; While(itr.hasNext()) { If(itr.next().equals(“gamma”)); Itr.remove(); //use of iterator for remove } //again display after deletion
  • 5. Itr.a1.iterator(); While(itr.hasNext()) System.out.println(itr.next()+ “ “); System.out.println(); //now use of listiterator to add gamma back to list ListIterator<String> litr =a1.listIterator(); //obtain list iterator While(litr.hasNext()) { If(litr.next().equals(“beta”)); Litr.add(“gamma”); //add element using list iterator. } //content after addition of gamma Litr=a1.listiterator(); While(litr.hasnext()) System.out.println(litr.next()+” “); System.out.println(); //use of listiterator to mdify the object being iterated. String str; Litr=a1.listIterator(); While(litr.hasnext()) { Str=litr.next(); If(str.equals(“alpha”); Litr.set(“A”); //use of iterator to change element Else if(str.equals(“beta”)
  • 6. Litr.set(“B”); } //use of list iterator to display in backward While(litr.hasprevious()) { System.out.println(litr.previous()+” “);// display list in reverse order } System.out.println(); } } For each Loop: To make iteration over array convenient we can use for each loop For(type var:arr) { Body of loop; } e.g double []arr={1,2,3,4,5,6,7,8}; int sum=0; for(double d:arr) { Sum +=d; } e.g int arr[]={ 12,13,14,15};
  • 7. for(int i:arr) { System.out.println(i); } Scanner class: To facilitate the user input we can use the java library scanner class. Scanner directly intract with system input buffer for values. e.g import java.util.Scanner; class Scan { Public static void main(String arr[]) { Scanner s=new Scanner(System.in); Int a=s.nextInt(); Int b=s.nextInt(); Some methods to be use with scanner class. nextByte(); will accept byte from input nextShort(); will accept short nextLong(); will accept long nextLine(); accept line of string nextBoolean(); accept boolean next float(); accept float
  • 8. Array: The similar data type elements, variable or objects can be stored in the array. Array can store homogenous data type variable. Array in C/C++ and Java are totally different. In java array are objects e.g int array[]; // here array is set to null there is nothing in the array if we want to the actual physical array on memory then we have to allocate the memory with new so int array[]; array[]=new int[12]; after this statement is executed arra will refer to array of 12 integer with no value but by default there is zero values in the array. Array can also be initialized when they are declared Like’ Int array[]={12,13,12,13,12,13,12,13,12,13}; Two dimensional array: Int twoD[][]=new int[4][5]; Class twoD { Public static void main(string arr[]) {
  • 9. Int twoD[][]=new int[4][5]; Int I,j,k=0; For(i=0;i<4;i++) For(j=0;j<5;j++) { twoD[i][j]=k; k++; } For(i=0;i<4;I++) { For(j=0;j<5;j++) System.out.println(twoD[i][j] +” “); System.out.println(); } } } e.g find the average ofinteger stored in array class Avg { Public static void main(String arr[]) { Double num[]={12.2,13.3,14.5,123.5,233.45,23.1}; Double result=0; Int i=0; For(i=0;i<5;i++)
  • 10. Result=result+num[i]; System.out.println(“average=”+result/6); } } } Irregular array: Int twoD[][]=new int [4][]; For first element memory is allocated for four element. For second dimensions we can allocate manually like twoD[0]= new int[1] twoD[1]= new int[2] twoD[2]= new int[3] twoD[3]= new int[4] so we can change the memory dynamically for column class twoD { Public static void main(String arr[]) { Int twoD[][]=ne twoD[0]= new int[1] twoD[0]= new int[1]; twoD[1]= new int[2]; twoD[2]= new int[3]; twoD[3]=new int[4]; int I,j,k=0; for(i=0;i<4;i++)
  • 11. for(j=0;j<i+1;j++) { twoD[i][j]=k; k++; } for(i=0;i<4;i++) for(j=0;j<i+1;j++) { System.out.println(twoD[i][j]+” “); System.out.println(); } } } e.g to find minimum and maximum in an array code: int num[]={12,13,11,1,-1,67,89,-90}; int min,max; min=max=num[0]; for(i=1;i<num.length;i++) { If(num[i]<min) Min=num[i]; If(num[i]>max) Max=num[i]; }
  • 12. System.out.println(“minmum and maximum;”+min+” “+max); } } e.g two print the common element in two array code: int arr1[]={4,5,6,2,1,3,4}; int arr2[]={12,13,14,15,3,2,4}; for(i=0;i<arr1.length;i++) for(j=0;j<arr2.length;j++) { If(arr1[i]==arr2[j]) { System.out.println(arr1[i]); } } e.g. program to sort the array import java.util.Arrays; class myArray { p.s.v.m(String arr[]) { Int[]myarr={3,2,3,2,3,2,4,5,12,0,-2}; Arrays.sort(myarr); For(int i=0;i<myarr.length;i++) {