Arrays in Java: Single and Multi-dimensional

  Quality Thought is recognized as the best software testing institute in Hyderabad, offering top-notch training in manual testing, automation testing, and full stack testing tools. With a focus on industry-relevant curriculum and hands-on practice, Quality Thought prepares students for real-world software testing challenges. The institute provides expert-led training on popular tools and frameworks like Selenium, TestNG, Jenkins, Git, Postman, JIRA, Maven, and Cucumber, covering both frontend and backend testing essentials.


Quality Thought’s Full Stack Testing course is specially designed to make students proficient in both manual testing fundamentals and automated testing tools, along with exposure to API testing, performance testing, and DevOps integration. The institute stands out for its experienced trainers, live projects, placement support, and flexible learning options including classroom and online modes.


Whether you are a fresher aiming for a job or a working professional looking to upskill, Quality Thought offers customized learning paths. Its strong industry connections ensure regular placement drives and job interview 

Arrays in Java: Single and Multi-dimensional

In Java, an array is a data structure that stores multiple values of the same data type in a single variable. Arrays are used to store a fixed-size sequence of elements.


Single-Dimensional Arrays

A single-dimensional array is like a list. It holds a sequence of elements in a linear form.


Syntax:


java

Copy

Edit

int[] numbers = new int[5];

Here, numbers is an array that can hold 5 integers. You can also initialize it directly:


java

Copy

Edit

int[] numbers = {10, 20, 30, 40, 50};

Accessing elements:


java

Copy

Edit

System.out.println(numbers[0]); // prints 10

Multi-Dimensional Arrays

A multi-dimensional array is like an array of arrays. The most common is the two-dimensional array, used to represent matrices or tables.


Syntax:


java

Copy

Edit

int[][] matrix = new int[3][3];

This creates a 3x3 matrix. Initialization example:


java

Copy

Edit

int[][] matrix = {

  {1, 2, 3},

  {4, 5, 6},

  {7, 8, 9}

};

Accessing elements:


java

Copy

Edit

System.out.println(matrix[1][2]); // prints 6

You can also create jagged arrays, where each row can have different column sizes.


Summary:

Single-dimensional arrays store data in a linear format.


Multi-dimensional arrays (2D, 3D, etc.) store data in a grid-like format.


Arrays in Java are zero-indexed, and their size is fixed once declared.


Arrays are useful for storing collections of data efficiently in structured forms.


Unlock more with Plus


Read More

Java Data Types and Variables

Loops in Java: for, while, do-while





Comments

Popular posts from this blog

What is Tosca and what is it used for?

Compute Engine (VMs)

What is Software Testing