SlideShare a Scribd company logo
Module 5     Arrays  
 
  Arrays •  Java array is an ordered collection of primitives,  object references, or other arrays.   •  A structure that holds multiple values of  the same type. •  An array is an object; it is created with new
To create an array follow three steps Declaration  Construction Initialization
Declaration Declaration tell the array’s name and what type its  element will be. int[]ints;  //declare array of primitive types double[] dubs; Dimension[] dims;  //declare array of object reference Float[][]twodee; //declare a two dimensional array
Construction Notice the declaration doesnot specify the size of array, size is specified at runtime when array is allocated  via new keyword . int[] ints; ints=new int[25]; Use the new keyword to create an array object.
Declaration and construction performed in single  line as  int[] ints=new int[25];
Initialization When the array is constructed its elements are  automatically initialized to their default value Element type Initial Value byte 0 short 0 i nt   0 long 0L float 0.0f double 0.0d char ‘\u0000’ b oolean false object reference   null
T o initialize an array to values other than above  combine declaration,construction and initialization  into single step . Implicit assigning of values boolean[] answers = { true, false, true, true, false }; float[]diameters={1.1f,2.2f,3.3f,4.4f,5.5f};    Explicit assigning of values long[] squares; squares=new long[6000]; for(int i=0;i<6000;i++){ squares[i]=i*i; }
Accessing an Array Element for (int i = 0; i < anArray.length; i++) { anArray[i] = i; System.out.print(anArray[i] + &quot; &quot;);   }   Note: Java array’s index always start at 0.
Getting the Size of an Array arrayname.length Note :length is not a method. length is a property  provided by the Java platform for all arrays.
 
Example   ArrayOfArraysDemo
  Array Bounds All array subscripts begin at 0: int list[] = new int [10]; for (int i = 0; i < list.length; i++) { System.out.println(list[i]); }
  Array Resizing •  Cannot resize an array •  Can use the same reference variable to refer to an  entirely new array:  int  elements[]  =  new  int[6]; elements  =  new  int[10]; Example   ArrayDemo.java
Example  ArrayCopyDemo

More Related Content

What's hot (20)

PPT
2 arrays
trixiacruz
 
PPT
Arrays
emartinez.romero
 
PPTX
Array in C# 3.5
Gopal Ji Singh
 
PDF
intorduction to Arrays in java
Muthukumaran Subramanian
 
PPTX
Array lecture
Joan Saño
 
PPTX
Module 7 : Arrays
Prem Kumar Badri
 
PPTX
Java arrays
Jin Castor
 
PPT
Java: Introduction to Arrays
Tareq Hasan
 
PDF
Array and Collections in c#
Umar Farooq
 
PPTX
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 
PDF
Lecture 7- Iterator and for loop over arrays
Syed Afaq Shah MACS CP
 
PPTX
Arrays C#
Raghuveer Guthikonda
 
PPTX
Arrays in java language
Hareem Naz
 
PDF
Java Arrays
OXUS 20
 
PPTX
2CPP06 - Arrays and Pointers
Michael Heron
 
PPTX
Two-dimensional array in java
Talha mahmood
 
PDF
An Introduction to Programming in Java: Arrays
Martin Chapman
 
PPTX
Data structures and algorithms arrays
chauhankapil
 
PPTX
Arrays in Java
Abhilash Nair
 
2 arrays
trixiacruz
 
Array in C# 3.5
Gopal Ji Singh
 
intorduction to Arrays in java
Muthukumaran Subramanian
 
Array lecture
Joan Saño
 
Module 7 : Arrays
Prem Kumar Badri
 
Java arrays
Jin Castor
 
Java: Introduction to Arrays
Tareq Hasan
 
Array and Collections in c#
Umar Farooq
 
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 
Lecture 7- Iterator and for loop over arrays
Syed Afaq Shah MACS CP
 
Arrays in java language
Hareem Naz
 
Java Arrays
OXUS 20
 
2CPP06 - Arrays and Pointers
Michael Heron
 
Two-dimensional array in java
Talha mahmood
 
An Introduction to Programming in Java: Arrays
Martin Chapman
 
Data structures and algorithms arrays
chauhankapil
 
Arrays in Java
Abhilash Nair
 

Viewers also liked (8)

PPT
Barrons
shenchengfei
 
DOC
User manual
shenchengfei
 
PPT
Md11 gui event handling
Rakesh Madugula
 
PDF
托福博客网&Zinch中国赠送书目录201203
shenchengfei
 
PDF
101017cnw2sa
shenchengfei
 
PPT
Test
shenchengfei
 
PPT
Md03 - part3
Rakesh Madugula
 
PPT
Md09 multithreading
Rakesh Madugula
 
Barrons
shenchengfei
 
User manual
shenchengfei
 
Md11 gui event handling
Rakesh Madugula
 
托福博客网&Zinch中国赠送书目录201203
shenchengfei
 
101017cnw2sa
shenchengfei
 
Md03 - part3
Rakesh Madugula
 
Md09 multithreading
Rakesh Madugula
 
Ad

Similar to Md05 arrays (20)

DOCX
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
PDF
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
PDF
Array
Ravi_Kant_Sahu
 
PPT
ch06.ppt
AqeelAbbas94
 
PPT
ch06.ppt
ansariparveen06
 
PPT
array Details
shivas379526
 
PPT
ch06.ppt
chandrasekar529044
 
PPT
17-Arrays en java presentación documento
DiegoGamboaSafla
 
PPTX
Arrays in programming
TaseerRao
 
PDF
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
DOCX
Java R20 - UNIT-3.docx
Pamarthi Kumar
 
PPTX
Arrays in java.pptx
Nagaraju Pamarthi
 
PPT
Data Structure Midterm Lesson Arrays
Maulen Bale
 
PPTX
ARRAYS.pptx
akila m
 
PPT
ARRAYS.ppt
surajthakur474818
 
PPTX
Java Array String
Manish Tiwari
 
PPT
ARRAYS in java with in details presentation.ppt
AshokRachapalli1
 
PPT
ARRAYSinJavaProgramming_Introduction.ppt
cluttertans
 
PPT
ARRAYS.ppt
coding9
 
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
ch06.ppt
AqeelAbbas94
 
ch06.ppt
ansariparveen06
 
array Details
shivas379526
 
17-Arrays en java presentación documento
DiegoGamboaSafla
 
Arrays in programming
TaseerRao
 
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
Java R20 - UNIT-3.docx
Pamarthi Kumar
 
Arrays in java.pptx
Nagaraju Pamarthi
 
Data Structure Midterm Lesson Arrays
Maulen Bale
 
ARRAYS.pptx
akila m
 
ARRAYS.ppt
surajthakur474818
 
Java Array String
Manish Tiwari
 
ARRAYS in java with in details presentation.ppt
AshokRachapalli1
 
ARRAYSinJavaProgramming_Introduction.ppt
cluttertans
 
ARRAYS.ppt
coding9
 
Ad

More from Rakesh Madugula (10)

PPT
New features and enhancement
Rakesh Madugula
 
PPT
Md13 networking
Rakesh Madugula
 
PPT
Md121 streams
Rakesh Madugula
 
PPT
Md10 building java gu is
Rakesh Madugula
 
PPT
Md08 collection api
Rakesh Madugula
 
PPT
Md07 exceptions&assertion
Rakesh Madugula
 
PPT
Md06 advance class features
Rakesh Madugula
 
PPT
Md04 flow control
Rakesh Madugula
 
PPT
Md02 - Getting Started part-2
Rakesh Madugula
 
PPT
A begineers guide of JAVA - Getting Started
Rakesh Madugula
 
New features and enhancement
Rakesh Madugula
 
Md13 networking
Rakesh Madugula
 
Md121 streams
Rakesh Madugula
 
Md10 building java gu is
Rakesh Madugula
 
Md08 collection api
Rakesh Madugula
 
Md07 exceptions&assertion
Rakesh Madugula
 
Md06 advance class features
Rakesh Madugula
 
Md04 flow control
Rakesh Madugula
 
Md02 - Getting Started part-2
Rakesh Madugula
 
A begineers guide of JAVA - Getting Started
Rakesh Madugula
 

Recently uploaded (20)

PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 

Md05 arrays

  • 1. Module 5 Arrays  
  • 2.  
  • 3. Arrays • Java array is an ordered collection of primitives, object references, or other arrays. • A structure that holds multiple values of the same type. • An array is an object; it is created with new
  • 4. To create an array follow three steps Declaration Construction Initialization
  • 5. Declaration Declaration tell the array’s name and what type its element will be. int[]ints; //declare array of primitive types double[] dubs; Dimension[] dims; //declare array of object reference Float[][]twodee; //declare a two dimensional array
  • 6. Construction Notice the declaration doesnot specify the size of array, size is specified at runtime when array is allocated via new keyword . int[] ints; ints=new int[25]; Use the new keyword to create an array object.
  • 7. Declaration and construction performed in single line as int[] ints=new int[25];
  • 8. Initialization When the array is constructed its elements are automatically initialized to their default value Element type Initial Value byte 0 short 0 i nt 0 long 0L float 0.0f double 0.0d char ‘\u0000’ b oolean false object reference null
  • 9. T o initialize an array to values other than above combine declaration,construction and initialization into single step . Implicit assigning of values boolean[] answers = { true, false, true, true, false }; float[]diameters={1.1f,2.2f,3.3f,4.4f,5.5f};  Explicit assigning of values long[] squares; squares=new long[6000]; for(int i=0;i<6000;i++){ squares[i]=i*i; }
  • 10. Accessing an Array Element for (int i = 0; i < anArray.length; i++) { anArray[i] = i; System.out.print(anArray[i] + &quot; &quot;);   }   Note: Java array’s index always start at 0.
  • 11. Getting the Size of an Array arrayname.length Note :length is not a method. length is a property provided by the Java platform for all arrays.
  • 12.  
  • 13. Example ArrayOfArraysDemo
  • 14. Array Bounds All array subscripts begin at 0: int list[] = new int [10]; for (int i = 0; i < list.length; i++) { System.out.println(list[i]); }
  • 15. Array Resizing • Cannot resize an array • Can use the same reference variable to refer to an entirely new array: int elements[] = new int[6]; elements = new int[10]; Example ArrayDemo.java