SlideShare a Scribd company logo
Arrays in Java | Edureka
Array in Java
Types of Arrays
Topics For Today’s Discussion
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Topics for Today’s Session
DeclaringAccessingUpdatingCreatingWorking with Array
Sorting in Arrays
Searching in Arrays
Java Arrays
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Array
Array is a static
Data Structure
Contains
collections of
homogenous
elements
All the
elements are
stored under
one variable
name
It occupies a
contiguous
memory location
Types of Arrays
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Types Of Arrays
01Single
Dimensional
Single Dimensional or
1-D array is a type of
linear array in which
elements are stored in
a continuous row
02Two
Dimensional
Two Dimensional or 2-D
array is a type of
matrix in which
elements are stored in
rows and columns
03Multi
Dimensional
Multi Dimensional
array is a type of
nested array
Working With Arrays
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Working With Arrays – 1D
arrayRefVar = new dataType[arraySize];
=myArray new int[5]
Declaring and Initializing an One Dimensional Array
datatype[] arrayRefVar = new dataType[arraySize];
=int[5] myArray new int[5]
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Working With Arrays – 1D
myArray
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
=myArray[0] 10
Declaring and Initializing an One Dimensional Array
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Working With Arrays – 1D
myArray
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
=myArray[2]
10
30
=myArray[3] 40
=myArray[4] 50
=myArray[1] 20
Declaring and Initializing an One Dimensional Array
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
myArray
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
10 30 40 5020
Working With Arrays – 1D
Declaring and Initializing an One Dimensional Array
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
10 30 40 5020
Working With Arrays – 1D
dataType[] arrayRefVar = new dataType{e1,e2,e3,…,eN};
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
=int[] myArray new int{10,20,30,40,50}
Declaring and Initializing an One Dimensional Array
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]
10 30 40 5020
Working With Arrays – 1D
int[] myArray
dataType[] arrayRefVar = new dataType{e1,e2,e3,…,eN};
Declaring and Initializing an One Dimensional Array
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Working With Arrays – 1D
Accessing a specific array element
myArray[0]
myArray[1]
myArray[2]
myArray[3]
myArray[4]
10
30
40
50
20
arrayRefVar[index]
myArray[4]
myArray[1]
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
100
Working With Arrays – 1D
Accessing a specific array element
myArray[0]
myArray[1]
myArray[2]
myArray[3]
myArray[4]
10
30
40
50
20
arrayRefVar[index]
myArray[4]
myArray[1]
Updating a specific array element
arrayRefVar[index] = newValue
myArray[4] = 100
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
myArray[4] = 100
Working With Arrays – 1D
Accessing a specific array element
myArray[0]
myArray[1]
myArray[2]
myArray[3]
myArray[4]
10
30
50
20
arrayRefVar[index]
myArray[4]
myArray[1]
Updating a specific array element
arrayRefVar[index] = newValue
100
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Working With Arrays – 2D
Declaring and Initializing an Two Dimensional Array
datatype[][] arrayRefVar = new dataType[row][col];
=int[][] myArray new int[2][2]
myArray[0][0] myArray[0][1]
myArray[1][0] myArray[1][1]
=myArray[0][0] 100
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
myArray[0][0] myArray[0][1]
myArray[1][0] myArray[1][1]
Working With Arrays – 2D
Declaring and Initializing an Two Dimensional Array
datatype[][] arrayRefVar = new dataType[row][col];
=int[][] myArray new int[2][2]
=myArray[0][1] 200
100 =myArray[1][0] 300
=myArray[1][1] 400
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
myArray[0][0] myArray[0][1]
myArray[1][0] myArray[1][1]
Working With Arrays – 2D
Declaring and Initializing an Two Dimensional Array
datatype[][] arrayRefVar = new dataType[row][col];
=int[][] myArray new int[2][2]
100 200
300 400
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
564
myArray[0][0] myArray[0][1]
myArray[1][0] myArray[1][1]
Working With Arrays – 2D
arrayRefVar[row][col]
100 200
300 400
Accessing a specific array element
myArray[0][1]
Updating a specific array element
arrayRefVar[row][col] = newValue
myArray[0][1] = 564
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
myArray[0][1] = 564
myArray[0][0] myArray[0][1]
myArray[1][0] myArray[1][1]
Working With Arrays – 2D
arrayRefVar[row][col]
100
300 400
Accessing a specific array element
myArray[0][1]
Updating a specific array element
arrayRefVar[row][col] = newValue
564
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Operations With Arrays
1 2 3
6
987
4 5
1 2 1
3
271
5 4
Addition of Matrices
a[3][3] b[3][3]
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Operations With Arrays
1 2 3
6
987
4 5
1 2 1
3
271
5 4
2 4 4
9
11158
9 9
a[3][3]
b[3][3]
c[3][3]
int[][] c = new int[rows][columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
c[i][j] = a[i][j] + b[i][j];
}
}
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
1 2 3
6
987
4 5
1 2 1
3
271
5 4
Division
a[3][3] b[3][3]
Operations With Arrays
Multiplication
Subtraction
Sorting in Arrays
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Sorting in Array
Java offers various sorting algorithms that helps in putting elements of a list in a certain order
Bubble Sort Insertion Sort Merge Sort
Quick SortSelection Sort
Types of Sorting Algorithms
Merge SortQuick SortInsertion SortSelection SortBubble Sort
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4 1 10 -3 12
4 1 10 -3 12
1 4 10 -3 12
1 4 10 -3 12
1 4 -3 10 12
1 4 -3 10 12
1 -3 4 10 12
1 -3 4 10 12
1 -3 4 10 12
-3 1 4 10 12
-3 1 4 10 12
void bubbleSort(int arr[])
{
int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
{
// swap temp and arr[i]
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
Merge SortQuick SortInsertion SortSelection SortBubble Sort
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4 1 10 -3 12
4 1 10 -3 12
-3 1 10 4 12
-3 1 10 4 12
-3 1 4 10 12
void selectionSort(int arr[])
{
int n = arr.length;
// One by one move boundary of unsorted subarray
for (int i = 0; i < n-1; i++)
{
// Find the minimum element in unsorted array
int min_idx = i;
for (int j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
// Swap the found minimum element with the first element
int temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
}
}
Merge SortQuick SortInsertion SortSelection SortBubble Sort
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4 1 10 -3 12
4 1 10 -3 12
1 4 10 -3 12
1 4 10 -3 12
-3 1 4 10 12
public static int[] insertionSort(int[] input){
int temp;
for (int i = 1; i < input.length; i++) {
for(int j = i ; j > 0 ; j--){
if(input[j] < input[j-1]){
// Swap with the smallest value
temp = input[j];
input[j] = input[j-1];
input[j-1] = temp;
}
}
}
return input;
}
-3 1 4 10 12
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
2 6 7 4 1 -2 8 4 3
2 6 7 4 1 -2 8 4 3
2 7 3 1 -2 8 4 46
2 1 6 7 -2 8 4 43
2 1 -2 4 6 8 7 43
2 1 -2 4 4 8 7 63
private void quickSort(int low, int high) {
int i = low;
int j = high;
// pivot is middle index
int pivot = input[low + (high - low) / 2];
// Divide into two arrays
while (i <= j) {
while (input[i] < pivot) {
i++;
}
while (input[j] > pivot) {
j--;
}
if (i <= j) {
swap(i, j);
// move index to next position on both sides
i++;
j--;
}
}
Merge SortQuick SortInsertion SortSelection SortBubble Sort
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
2 6 7 4 1 -2 8 4 3
2 6 7 4 1 -2 8 4 3
2 7 3 1 -2 8 4 46
2 1 6 7 -2 8 4 43
2 1 -2 4 6 8 7 43
2 1 -2 4 4 8 7 63
swap(i, j);
// move index to next position on both sides
i++;
j--;
}
}
Merge SortQuick SortInsertion SortSelection SortBubble Sort
// calls quickSort() method recursively
if (low < j) {
quickSort(low, j);
}
if (i < high) {
quickSort(i, high);
}
}
private void swap(int i, int j) {
int temp = input[i];
input[i] = input[j];
input[j] = temp;
}
}
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Merge SortQuick SortInsertion SortSelection SortBubble Sort
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
1 4 10 -3 12
1 4 10 -3 12
-3 1 4 10 12
// Merges two subarrays of arr[]
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void mergeSort(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
1 4 10 -3 12
1 4 10 -3 12
-3 1 4 10 12
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
4 1 10 -3 12
Merge SortQuick SortInsertion SortSelection SortBubble Sort
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
1 4 10 -3 12
1 4 10 -3 12
-3 1 4 10 12
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
k++;
}
Merge SortQuick SortInsertion SortSelection SortBubble Sort
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
4 1 10 -3 12
1 4 10 -3 12
1 4 10 -3 12
-3 1 4 10 12
k++;
}
}
Merge SortQuick SortInsertion SortSelection SortBubble Sort
// Main function that sorts arr[l..r] using
// merge()
void sort(int arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
Searching in Arrays
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Sorting in Array
Java offers various sorting algorithms that helps in putting elements of a list in a certain order
Types of Searching Algorithms
Binary SearchLinear Search
Binary SearchLinear Search
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
4
1
10
-3
12
static int search(int arr[], int n, int x)
{
for (int i = 0; i < n; i++)
{
// Return the index of the element if the
element
// is found
if (arr[i] == x)
return i;
}
// return -1 if the element is not found
return -1;
}
Binary SearchLinear Search
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
2 6 7 9 15 26 50 79 83
2 6 7 9 15 26 50 79 83
15 26 50 79 83
int binarySearch(int arr[], int l, int r, int x)
{
if (r>=l)
{
int mid = l + (r - l)/2;
// If the element is present at the
// middle itself
if (arr[mid] == x)
return mid;
// If element is smaller than mid, then
// it can only be present in left subarray
if (arr[mid] > x)
return binarySearch(arr, l, mid-1, x);
// Else the element can only be present
// in right subarray
return binarySearch(arr, mid+1, r, x);
}
Arrays in Java | Edureka

More Related Content

What's hot (20)

Java Arrays
Java ArraysJava Arrays
Java Arrays
Jussi Pohjolainen
 
Java Strings
Java StringsJava Strings
Java Strings
RaBiya Chaudhry
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
Santosh Kumar Kar
 
Java
JavaJava
Java
s4al_com
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
Prof. Erwin Globio
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
Sourabh Sahu
 
mysql-Tutorial with Query presentation.ppt
mysql-Tutorial with Query presentation.pptmysql-Tutorial with Query presentation.ppt
mysql-Tutorial with Query presentation.ppt
aptechaligarh
 
React render props
React render propsReact render props
React render props
Saikat Samanta
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
Hitesh-Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
Prof. Erwin Globio
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
mysql-Tutorial with Query presentation.ppt
mysql-Tutorial with Query presentation.pptmysql-Tutorial with Query presentation.ppt
mysql-Tutorial with Query presentation.ppt
aptechaligarh
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
Hitesh-Java
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 

Similar to Arrays in Java | Edureka (20)

Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdhCh-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
zakiking612
 
ajava arrays topic brief explanation data
ajava arrays topic brief explanation dataajava arrays topic brief explanation data
ajava arrays topic brief explanation data
VenkatasaireddyMarth
 
Lecture no 9.ppt operating system semester four
Lecture  no 9.ppt operating system semester fourLecture  no 9.ppt operating system semester four
Lecture no 9.ppt operating system semester four
VaibhavBhagwat18
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
manish kumar
 
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | EdurekaJava Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
Edureka!
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
SatyajeetGaur3
 
SessionPlans_f3efa1.6 Array in java.pptx
SessionPlans_f3efa1.6 Array in java.pptxSessionPlans_f3efa1.6 Array in java.pptx
SessionPlans_f3efa1.6 Array in java.pptx
businessmarketing100
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
MSohaib24
 
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptxpreparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
tirthasurani118866
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
trupti1976
 
Selection sort
Selection sortSelection sort
Selection sort
Abdelrahman Saleh
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
rohassanie
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
MaruMengesha
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Nanthini Kempaiyan
 
Array
ArrayArray
Array
Kongu Engineering College, Perundurai, Erode
 
DSA 103 Object Oriented Programming :: Week 5
DSA 103 Object Oriented Programming :: Week 5DSA 103 Object Oriented Programming :: Week 5
DSA 103 Object Oriented Programming :: Week 5
Ferdin Joe John Joseph PhD
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
shafat6712
 
Array
ArrayArray
Array
Ravi_Kant_Sahu
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
 
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdhCh-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
zakiking612
 
ajava arrays topic brief explanation data
ajava arrays topic brief explanation dataajava arrays topic brief explanation data
ajava arrays topic brief explanation data
VenkatasaireddyMarth
 
Lecture no 9.ppt operating system semester four
Lecture  no 9.ppt operating system semester fourLecture  no 9.ppt operating system semester four
Lecture no 9.ppt operating system semester four
VaibhavBhagwat18
 
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | EdurekaJava Programming | Java Tutorial For Beginners | Java Training | Edureka
Java Programming | Java Tutorial For Beginners | Java Training | Edureka
Edureka!
 
SessionPlans_f3efa1.6 Array in java.pptx
SessionPlans_f3efa1.6 Array in java.pptxSessionPlans_f3efa1.6 Array in java.pptx
SessionPlans_f3efa1.6 Array in java.pptx
businessmarketing100
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
MSohaib24
 
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptxpreparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
preparecallablepptx__2023_09_11_14_40_58pptx__2024_09_23_11_14_59.pptx
tirthasurani118866
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
MaruMengesha
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
 
Ad

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 

Arrays in Java | Edureka

  • 2. Array in Java Types of Arrays Topics For Today’s Discussion JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Topics for Today’s Session DeclaringAccessingUpdatingCreatingWorking with Array Sorting in Arrays Searching in Arrays
  • 4. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Array Array is a static Data Structure Contains collections of homogenous elements All the elements are stored under one variable name It occupies a contiguous memory location
  • 6. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Types Of Arrays 01Single Dimensional Single Dimensional or 1-D array is a type of linear array in which elements are stored in a continuous row 02Two Dimensional Two Dimensional or 2-D array is a type of matrix in which elements are stored in rows and columns 03Multi Dimensional Multi Dimensional array is a type of nested array
  • 8. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Working With Arrays – 1D arrayRefVar = new dataType[arraySize]; =myArray new int[5] Declaring and Initializing an One Dimensional Array datatype[] arrayRefVar = new dataType[arraySize]; =int[5] myArray new int[5]
  • 9. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Working With Arrays – 1D myArray myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] =myArray[0] 10 Declaring and Initializing an One Dimensional Array
  • 10. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Working With Arrays – 1D myArray myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] =myArray[2] 10 30 =myArray[3] 40 =myArray[4] 50 =myArray[1] 20 Declaring and Initializing an One Dimensional Array
  • 11. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training myArray myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] 10 30 40 5020 Working With Arrays – 1D Declaring and Initializing an One Dimensional Array
  • 12. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 10 30 40 5020 Working With Arrays – 1D dataType[] arrayRefVar = new dataType{e1,e2,e3,…,eN}; myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] =int[] myArray new int{10,20,30,40,50} Declaring and Initializing an One Dimensional Array
  • 13. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] 10 30 40 5020 Working With Arrays – 1D int[] myArray dataType[] arrayRefVar = new dataType{e1,e2,e3,…,eN}; Declaring and Initializing an One Dimensional Array
  • 14. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Working With Arrays – 1D Accessing a specific array element myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] 10 30 40 50 20 arrayRefVar[index] myArray[4] myArray[1]
  • 15. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 100 Working With Arrays – 1D Accessing a specific array element myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] 10 30 40 50 20 arrayRefVar[index] myArray[4] myArray[1] Updating a specific array element arrayRefVar[index] = newValue myArray[4] = 100
  • 16. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training myArray[4] = 100 Working With Arrays – 1D Accessing a specific array element myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] 10 30 50 20 arrayRefVar[index] myArray[4] myArray[1] Updating a specific array element arrayRefVar[index] = newValue 100
  • 17. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Working With Arrays – 2D Declaring and Initializing an Two Dimensional Array datatype[][] arrayRefVar = new dataType[row][col]; =int[][] myArray new int[2][2] myArray[0][0] myArray[0][1] myArray[1][0] myArray[1][1] =myArray[0][0] 100
  • 18. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training myArray[0][0] myArray[0][1] myArray[1][0] myArray[1][1] Working With Arrays – 2D Declaring and Initializing an Two Dimensional Array datatype[][] arrayRefVar = new dataType[row][col]; =int[][] myArray new int[2][2] =myArray[0][1] 200 100 =myArray[1][0] 300 =myArray[1][1] 400
  • 19. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training myArray[0][0] myArray[0][1] myArray[1][0] myArray[1][1] Working With Arrays – 2D Declaring and Initializing an Two Dimensional Array datatype[][] arrayRefVar = new dataType[row][col]; =int[][] myArray new int[2][2] 100 200 300 400
  • 20. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 564 myArray[0][0] myArray[0][1] myArray[1][0] myArray[1][1] Working With Arrays – 2D arrayRefVar[row][col] 100 200 300 400 Accessing a specific array element myArray[0][1] Updating a specific array element arrayRefVar[row][col] = newValue myArray[0][1] = 564
  • 21. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training myArray[0][1] = 564 myArray[0][0] myArray[0][1] myArray[1][0] myArray[1][1] Working With Arrays – 2D arrayRefVar[row][col] 100 300 400 Accessing a specific array element myArray[0][1] Updating a specific array element arrayRefVar[row][col] = newValue 564
  • 22. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Operations With Arrays 1 2 3 6 987 4 5 1 2 1 3 271 5 4 Addition of Matrices a[3][3] b[3][3]
  • 23. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Operations With Arrays 1 2 3 6 987 4 5 1 2 1 3 271 5 4 2 4 4 9 11158 9 9 a[3][3] b[3][3] c[3][3] int[][] c = new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { c[i][j] = a[i][j] + b[i][j]; } }
  • 24. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 1 2 3 6 987 4 5 1 2 1 3 271 5 4 Division a[3][3] b[3][3] Operations With Arrays Multiplication Subtraction
  • 26. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Sorting in Array Java offers various sorting algorithms that helps in putting elements of a list in a certain order Bubble Sort Insertion Sort Merge Sort Quick SortSelection Sort Types of Sorting Algorithms
  • 27. Merge SortQuick SortInsertion SortSelection SortBubble Sort JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 4 1 10 -3 12 1 4 10 -3 12 1 4 10 -3 12 1 4 -3 10 12 1 4 -3 10 12 1 -3 4 10 12 1 -3 4 10 12 1 -3 4 10 12 -3 1 4 10 12 -3 1 4 10 12 void bubbleSort(int arr[]) { int n = arr.length; for (int i = 0; i < n-1; i++) for (int j = 0; j < n-i-1; j++) if (arr[j] > arr[j+1]) { // swap temp and arr[i] int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } }
  • 28. Merge SortQuick SortInsertion SortSelection SortBubble Sort JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 4 1 10 -3 12 -3 1 10 4 12 -3 1 10 4 12 -3 1 4 10 12 void selectionSort(int arr[]) { int n = arr.length; // One by one move boundary of unsorted subarray for (int i = 0; i < n-1; i++) { // Find the minimum element in unsorted array int min_idx = i; for (int j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element with the first element int temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp; } }
  • 29. Merge SortQuick SortInsertion SortSelection SortBubble Sort JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 4 1 10 -3 12 1 4 10 -3 12 1 4 10 -3 12 -3 1 4 10 12 public static int[] insertionSort(int[] input){ int temp; for (int i = 1; i < input.length; i++) { for(int j = i ; j > 0 ; j--){ if(input[j] < input[j-1]){ // Swap with the smallest value temp = input[j]; input[j] = input[j-1]; input[j-1] = temp; } } } return input; } -3 1 4 10 12
  • 30. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 2 6 7 4 1 -2 8 4 3 2 6 7 4 1 -2 8 4 3 2 7 3 1 -2 8 4 46 2 1 6 7 -2 8 4 43 2 1 -2 4 6 8 7 43 2 1 -2 4 4 8 7 63 private void quickSort(int low, int high) { int i = low; int j = high; // pivot is middle index int pivot = input[low + (high - low) / 2]; // Divide into two arrays while (i <= j) { while (input[i] < pivot) { i++; } while (input[j] > pivot) { j--; } if (i <= j) { swap(i, j); // move index to next position on both sides i++; j--; } } Merge SortQuick SortInsertion SortSelection SortBubble Sort
  • 31. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 2 6 7 4 1 -2 8 4 3 2 6 7 4 1 -2 8 4 3 2 7 3 1 -2 8 4 46 2 1 6 7 -2 8 4 43 2 1 -2 4 6 8 7 43 2 1 -2 4 4 8 7 63 swap(i, j); // move index to next position on both sides i++; j--; } } Merge SortQuick SortInsertion SortSelection SortBubble Sort // calls quickSort() method recursively if (low < j) { quickSort(low, j); } if (i < high) { quickSort(i, high); } } private void swap(int i, int j) { int temp = input[i]; input[i] = input[j]; input[j] = temp; } }
  • 32. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Merge SortQuick SortInsertion SortSelection SortBubble Sort 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 1 4 10 -3 12 1 4 10 -3 12 -3 1 4 10 12 // Merges two subarrays of arr[] // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void mergeSort(int arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ int L[] = new int [n1]; int R[] = new int [n2]; /*Copy data to temp arrays*/ for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j];
  • 33. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 1 4 10 -3 12 1 4 10 -3 12 -3 1 4 10 12 /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; 4 1 10 -3 12 Merge SortQuick SortInsertion SortSelection SortBubble Sort
  • 34. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 1 4 10 -3 12 1 4 10 -3 12 -3 1 4 10 12 /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } k++; } Merge SortQuick SortInsertion SortSelection SortBubble Sort
  • 35. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 4 1 10 -3 12 1 4 10 -3 12 1 4 10 -3 12 -3 1 4 10 12 k++; } } Merge SortQuick SortInsertion SortSelection SortBubble Sort // Main function that sorts arr[l..r] using // merge() void sort(int arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } }
  • 37. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Sorting in Array Java offers various sorting algorithms that helps in putting elements of a list in a certain order Types of Searching Algorithms Binary SearchLinear Search
  • 38. Binary SearchLinear Search JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 4 1 10 -3 12 static int search(int arr[], int n, int x) { for (int i = 0; i < n; i++) { // Return the index of the element if the element // is found if (arr[i] == x) return i; } // return -1 if the element is not found return -1; }
  • 39. Binary SearchLinear Search JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 2 6 7 9 15 26 50 79 83 2 6 7 9 15 26 50 79 83 15 26 50 79 83 int binarySearch(int arr[], int l, int r, int x) { if (r>=l) { int mid = l + (r - l)/2; // If the element is present at the // middle itself if (arr[mid] == x) return mid; // If element is smaller than mid, then // it can only be present in left subarray if (arr[mid] > x) return binarySearch(arr, l, mid-1, x); // Else the element can only be present // in right subarray return binarySearch(arr, mid+1, r, x); }