0% found this document useful (0 votes)
3 views

java array

The document provides an overview of arrays in programming, explaining that they are containers for storing multiple values of the same data type. It covers the declaration, initialization, and types of arrays, including one-dimensional and two-dimensional arrays, as well as operations like copying and cloning. Additionally, it includes examples of creating arrays of objects and tasks related to managing records in arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

java array

The document provides an overview of arrays in programming, explaining that they are containers for storing multiple values of the same data type. It covers the declaration, initialization, and types of arrays, including one-dimensional and two-dimensional arrays, as well as operations like copying and cloning. Additionally, it includes examples of creating arrays of objects and tasks related to managing records in arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

By Ranjit Bhosale

By Ranjit Bhosale 11/11/2021 1


 Array is a container which can hold a fix
number of entities, which are of the of the
same type.

 Array is a collection of elements of same data


type.
e.g. array of integers, array of floats and
array of Strings.

 Arrays are used to store multiple values in a


single variable, instead of declaring separate
variables for each value.

By Ranjit Bhosale 11/11/2021 2


By Ranjit Bhosale 11/11/2021 3
 Array Data Structure.
 An array is a collection of items stored at
contiguous memory locations.

 Arrays of primitives stored in stack area.


 Arrays of reference types in java are stored in
heap area.

By Ranjit Bhosale 11/11/2021 4


 One Dimensional array
 How to declare an array with initialization.
int arr[]={1,2,3,4,5};

 How to declare without intializaion


e.g. int arr[]=new int[5];
Later initialization,
arr[0]=10;
arr[1]=20; etc.

By Ranjit Bhosale 11/11/2021 5


 The Two Dimensional Array in Java is
nothing but an Array of Arrays.

 In Java Two Dimensional Array, data stored in


row and columns, and

 we can access the record using both the row


index and column index (like an Excel File).

By Ranjit Bhosale 11/11/2021 6


By Ranjit Bhosale 11/11/2021 7
 How to get the length of an array.
 Create 1D integer array and display the
elements with index.
 Create 1D integer array and find the sum of
elements of it.
 Create 1D integer array and display the
elements in reverse order.
 Accept any int from user and search that int
in created array. Display position.
 Matrix :: sum of all elements

By Ranjit Bhosale 11/11/2021 8


Copying array.
System.arraycopy(Object src, int srcPos, Object dest, int
destPos, int length)
e.g. System.arraycopy(arr1, 0, arr2, 0, 5);

Cloning an Array in Java


Java array implements the Cloneable interface, we can create
the clone of the Java array.
Just call clone()

public class Arrays


java.util package
1. sort()
2. asList()
Returns a fixed-size list backed by the specified array.
3. int binarySearch(int[] a, int key)

By Ranjit Bhosale 11/11/2021 9


By Ranjit Bhosale 11/11/2021 10
Array of objects can be created.
Syntax

Class_Name obj[ ]= new Class_Name[Array_Length];


e.g. Student arr[]=new Student[3];

Suppose you have three objects of Students class let say


s1,s2,s3 they are stored like below
arr[0]=s1; arr[1]=s2; arr[2]=s3;
roll name marks

arr[0] 101 AAA 70.00

arr[1] 102 BBB 78.00

arr[2] 103 CCC 80.00

By Ranjit Bhosale 11/11/2021 11


▪ Create records of Student and store it into
array.

▪ Create records of Employees and store it into


array. Display the record of employee who
has max salary.

By Ranjit Bhosale 11/11/2021 12

You might also like