Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Arrays

Lesson 27 of 39 in the free Java notes on Siksha Sarovar, written by Rohit Jangra.

Array

An array is a continuous block of memory used to store multiple homogeneous (same type) values. In Java, Array is an Object.

Characteristics

Fixed Size: Defined at instantiation. Cannot be modified later. • Index Based: Starts from 0 to length - 1. • Homogeneous: Only same data type allowed.

Declaration & Instantiation

  1. Declaration: int[] x; or int x[];
  2. Instantiation: x = new int[5]; (Default values assigned: 0 for int, null for Objects).
  3. Single Line: int[] x = new int[5];
  4. Initialization: int[] x = {10, 20, 30};.
  5. Anonymous Array: new int[]{1, 2, 3}

Length Property

x.length: Returns size of the array.

Accessing Elements

  1. Limit: 0 to length-1.
  2. Exception: Accessing outside range throws ArrayIndexOutOfBoundsException.
  3. Loops:
  4. for(int i=0; i<x.length; i++)For-Each: for(int val : x) (Forward direction only).

Arrays Class

Present in java.util. Static helper methods. • Arrays.sort(arr): Sorts ascending. • Arrays.toString(arr): Printable string format.

Multi-Dimensional Array

Storing elements in rows and columns (Matrix). • Declaration: int[][] arr; • Instantiation: new int[3][3]; (3 Rows, 3 Cols). • Access: arr[row][col].