SlideShare a Scribd company logo
Arrays Basicfundamentaldatastructure.ppt
● This module is intend to develop basic skills in
creating arrays.
● Understand the importance of Arrays.
● Working with Single Dimensional Arrays.
● Working with multidimensional Arrays.
● Implementation of Arrays in real time.
● Using enhanced for loop.
● Passing and returning arrays from methods.
● Introduction to java.util.Arrays class.
Module Overview
2
 Uderstand the concept of arrays and create single
double dimensional arrays.
 Understand advantages and disadvantages of Arrays.
 Declare and create arrays of primitive, class, or array
types
 Explain why elements of an array are initialized
 Explain how to initialize the elements of an array
 Determine the number of elements in an array
 Accessing elements using enhanced for loop.
 Working with java.util.Arrays class.
Objectives
3
Array: An array is a collection of different values of
same data type which are stored in a single place
and identified by a single variable .Since it stores
multiple values ,array is termed as data structure.
 It stores a fixed-size sequential collection of elements
of the same type.
 Array elements are accessed using array index.
Array
4
Array Declaration
Array Declaration:
 First declare a variable to reference the array.
 Second step is to specify the type of array the
variable can reference.
Example:
double[] myList; // preferred way.
or
double myList[]; // works but not preferred way.
char s[]; Point p[]; Char[] s; Point[] p;
Create space for a reference.
 An array is an object; it is created with new.
Creating Arrays
Using new operator in order to create array.
arrayRefVar = new dataType[arraySize];
The above statement does two things:
 It creates an array using new
dataType[arraySize];
 It assigns the reference of the newly created array
to the variable arrayRefVar.
Above steps can be combined in one statement.
dataType[] arrayRefVar = new dataType[arraySize];
Creating Arrays(Cont…)
Alternative Way:
dataType[] arrayRefVar = {value0, value1, ...,
valuek};
The array elements are accessed through the
index. Array indices start from 0 to
arrayRefVar.length-1.
Creating an Array of Primitive Types.
Creating an Array of Objects.
Another example, an object array:
public Point[] createArray() {
Point[] p;
p = new Point[10];
for ( int i=0; i<10; i++ ) {
p[i] = new Point(i, i+1);
}
return p;
}
Creating an Array Object Continuation
 for or foreach loop can be used inorder to process
the elements of an array, because all of the elements
in an array are of the same type and the size of the
array is known.
Syntax of for:
for (int i = 1; i < array.length; i++) {
if (array[i] > max) max = array[i];
}
Syntax of for each:
for (double element: array) {
System.out.println(element);
}
Processing Arrays
Passing Arrays to Methods
 Like other values to (parameters)methods, arrays
also can be passed to methods.
Ex:
public static void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
printArray(new int[]{3, 1, 2, 6, 4, 2});//invoking an
array
Returning Arrays from methods
A method may also return an array like any other
value to the caller .
Public int[] reverse(int[] list) {
int[] result = new int[list.length];
for (int i = 0; i = result.length - 1;
i < list.length; i++, j--) {
result[j] = list[i];
}
result result;
}
The Array Class
 The java.util.Arrays class contains various static
methods for sorting , searching , comparing and
filling array elements.
 These methods are overloaded for all primitive
types.
 public static int binarySearch(Object[] a, Object
key)
 public static boolean equals(long[] a, long[] a2)
 public static void fill(int[] a, int val)
 public static void sort(Object[] a)
Excercise
 Create an application that will sort an array
elements in ascending order and descending.
 Create an application that will create a array
which contains elements in reverse order to that
of the original array.
 Create an application that will store elements of
one array into another.
 Thank You

More Related Content

PPTX
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 
PPTX
12. arrays
M H Buddhika Ariyaratne
 
PPTX
ch 7 single dimension array in oop .pptx
nilampatoliya
 
PDF
Java Arrays
OXUS 20
 
PDF
Java arrays (1)
Liza Abello
 
PPTX
07+08slide.pptx
MURADSANJOUM
 
PPTX
Arrays in java.pptx
Nagaraju Pamarthi
 
PPT
17-Arrays en java presentación documento
DiegoGamboaSafla
 
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 
ch 7 single dimension array in oop .pptx
nilampatoliya
 
Java Arrays
OXUS 20
 
Java arrays (1)
Liza Abello
 
07+08slide.pptx
MURADSANJOUM
 
Arrays in java.pptx
Nagaraju Pamarthi
 
17-Arrays en java presentación documento
DiegoGamboaSafla
 

Similar to Arrays Basicfundamentaldatastructure.ppt (20)

PDF
An Introduction to Programming in Java: Arrays
Martin Chapman
 
PPT
Array
PRN USM
 
PDF
Lecture 6 - Arrays
Syed Afaq Shah MACS CP
 
DOC
Data structure lecture 2
Abbott
 
PPTX
Arrays in programming
TaseerRao
 
PPTX
Arrays in Java with example and types of array.pptx
ashwinibhosale27
 
DOCX
Java R20 - UNIT-3.docx
Pamarthi Kumar
 
PPT
slidlecturlecturlecturlecturlecturlecturlecturlectures06.ppt
KierenReynolds3
 
PPT
Arrays in Java Programming Language slides
ssuser5d6130
 
PPT
Array1
Rajendran
 
PDF
Data structure lecture 2 (pdf)
Abbott
 
PDF
Java - Arrays Concepts
Victer Paul
 
PPT
Array.ppt
SbsOmit1
 
PPT
array.ppt
rajput0302
 
PPTX
Chap1 array
raksharao
 
PPT
STRINGS IN JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
Arrays in Java
Naz Abdalla
 
PDF
Core Java Programming Language (JSE) : Chapter V - Arrays
WebStackAcademy
 
PPTX
Java Programming
Nanthini Kempaiyan
 
DOCX
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
An Introduction to Programming in Java: Arrays
Martin Chapman
 
Array
PRN USM
 
Lecture 6 - Arrays
Syed Afaq Shah MACS CP
 
Data structure lecture 2
Abbott
 
Arrays in programming
TaseerRao
 
Arrays in Java with example and types of array.pptx
ashwinibhosale27
 
Java R20 - UNIT-3.docx
Pamarthi Kumar
 
slidlecturlecturlecturlecturlecturlecturlecturlectures06.ppt
KierenReynolds3
 
Arrays in Java Programming Language slides
ssuser5d6130
 
Array1
Rajendran
 
Data structure lecture 2 (pdf)
Abbott
 
Java - Arrays Concepts
Victer Paul
 
Array.ppt
SbsOmit1
 
array.ppt
rajput0302
 
Chap1 array
raksharao
 
Arrays in Java
Naz Abdalla
 
Core Java Programming Language (JSE) : Chapter V - Arrays
WebStackAcademy
 
Java Programming
Nanthini Kempaiyan
 
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
Ad

More from JyothiAmpally (19)

DOCX
node.js interview questions and answers.
JyothiAmpally
 
PPT
Exception and ErrorHandling in Java .ppt
JyothiAmpally
 
PPT
Java Strings methods and operations.ppt
JyothiAmpally
 
PPT
_Java__Expressions__and__FlowControl.ppt
JyothiAmpally
 
PPT
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
PPT
Java Operators explained _in __brief.ppt
JyothiAmpally
 
PPT
UML to Object Oriented Mapping java .ppt
JyothiAmpally
 
PPT
OOPS_AbstractClasses_explained__java.ppt
JyothiAmpally
 
PPT
Java_Identifiers_keywords_data_types.ppt
JyothiAmpally
 
PPT
Java_gui_with_AWT_and_its_components.ppt
JyothiAmpally
 
PPT
1. Introduction to HTML5.ppt
JyothiAmpally
 
PPT
01-basics-functions.ppt
JyothiAmpally
 
PPT
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
PPT
25-functions.ppt
JyothiAmpally
 
PPT
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
PPT
02-Java Technology Details.ppt
JyothiAmpally
 
PPT
01-Java Introduction.ppt
JyothiAmpally
 
PPT
01_What is Java.ppt
JyothiAmpally
 
DOCX
Spring security
JyothiAmpally
 
node.js interview questions and answers.
JyothiAmpally
 
Exception and ErrorHandling in Java .ppt
JyothiAmpally
 
Java Strings methods and operations.ppt
JyothiAmpally
 
_Java__Expressions__and__FlowControl.ppt
JyothiAmpally
 
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
Java Operators explained _in __brief.ppt
JyothiAmpally
 
UML to Object Oriented Mapping java .ppt
JyothiAmpally
 
OOPS_AbstractClasses_explained__java.ppt
JyothiAmpally
 
Java_Identifiers_keywords_data_types.ppt
JyothiAmpally
 
Java_gui_with_AWT_and_its_components.ppt
JyothiAmpally
 
1. Introduction to HTML5.ppt
JyothiAmpally
 
01-basics-functions.ppt
JyothiAmpally
 
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
25-functions.ppt
JyothiAmpally
 
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
02-Java Technology Details.ppt
JyothiAmpally
 
01-Java Introduction.ppt
JyothiAmpally
 
01_What is Java.ppt
JyothiAmpally
 
Spring security
JyothiAmpally
 
Ad

Recently uploaded (20)

PDF
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
High Ground Student Revision Booklet Preview
jpinnuck
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Understanding operators in c language.pptx
auteharshil95
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
High Ground Student Revision Booklet Preview
jpinnuck
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 

Arrays Basicfundamentaldatastructure.ppt

  • 2. ● This module is intend to develop basic skills in creating arrays. ● Understand the importance of Arrays. ● Working with Single Dimensional Arrays. ● Working with multidimensional Arrays. ● Implementation of Arrays in real time. ● Using enhanced for loop. ● Passing and returning arrays from methods. ● Introduction to java.util.Arrays class. Module Overview 2
  • 3.  Uderstand the concept of arrays and create single double dimensional arrays.  Understand advantages and disadvantages of Arrays.  Declare and create arrays of primitive, class, or array types  Explain why elements of an array are initialized  Explain how to initialize the elements of an array  Determine the number of elements in an array  Accessing elements using enhanced for loop.  Working with java.util.Arrays class. Objectives 3
  • 4. Array: An array is a collection of different values of same data type which are stored in a single place and identified by a single variable .Since it stores multiple values ,array is termed as data structure.  It stores a fixed-size sequential collection of elements of the same type.  Array elements are accessed using array index. Array 4
  • 5. Array Declaration Array Declaration:  First declare a variable to reference the array.  Second step is to specify the type of array the variable can reference. Example: double[] myList; // preferred way. or double myList[]; // works but not preferred way. char s[]; Point p[]; Char[] s; Point[] p; Create space for a reference.  An array is an object; it is created with new.
  • 6. Creating Arrays Using new operator in order to create array. arrayRefVar = new dataType[arraySize]; The above statement does two things:  It creates an array using new dataType[arraySize];  It assigns the reference of the newly created array to the variable arrayRefVar. Above steps can be combined in one statement. dataType[] arrayRefVar = new dataType[arraySize];
  • 7. Creating Arrays(Cont…) Alternative Way: dataType[] arrayRefVar = {value0, value1, ..., valuek}; The array elements are accessed through the index. Array indices start from 0 to arrayRefVar.length-1.
  • 8. Creating an Array of Primitive Types.
  • 9. Creating an Array of Objects. Another example, an object array: public Point[] createArray() { Point[] p; p = new Point[10]; for ( int i=0; i<10; i++ ) { p[i] = new Point(i, i+1); } return p; }
  • 10. Creating an Array Object Continuation
  • 11.  for or foreach loop can be used inorder to process the elements of an array, because all of the elements in an array are of the same type and the size of the array is known. Syntax of for: for (int i = 1; i < array.length; i++) { if (array[i] > max) max = array[i]; } Syntax of for each: for (double element: array) { System.out.println(element); } Processing Arrays
  • 12. Passing Arrays to Methods  Like other values to (parameters)methods, arrays also can be passed to methods. Ex: public static void printArray(int[] array) { for (int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); } } printArray(new int[]{3, 1, 2, 6, 4, 2});//invoking an array
  • 13. Returning Arrays from methods A method may also return an array like any other value to the caller . Public int[] reverse(int[] list) { int[] result = new int[list.length]; for (int i = 0; i = result.length - 1; i < list.length; i++, j--) { result[j] = list[i]; } result result; }
  • 14. The Array Class  The java.util.Arrays class contains various static methods for sorting , searching , comparing and filling array elements.  These methods are overloaded for all primitive types.  public static int binarySearch(Object[] a, Object key)  public static boolean equals(long[] a, long[] a2)  public static void fill(int[] a, int val)  public static void sort(Object[] a)
  • 15. Excercise  Create an application that will sort an array elements in ascending order and descending.  Create an application that will create a array which contains elements in reverse order to that of the original array.  Create an application that will store elements of one array into another.

Editor's Notes

  • #2: Instructor Notes:
  • #3: Instructor Notes: By the end of this module, participants should be able to: <Obj1> <Obj 2>
  • #4: Instructor Notes: