Unlock Your Python Backend Career: Build 30 Projects in 30 Days. Join now for just $54

Arrays in Java

Type of Arrays in Java

The Java array is divided into two main types which then expands in different varieties of arrays. Here's a breakdown of the type of arrays:

  1. Regular Array: Regular array is further divided into 1-dimensional, 2- 2-dimensional, 3-dimensional arrays, and so on.

  2. Jagged Array: Jagged is an array of arrays such that member arrays can be of different sizes, i.e., we can create 2-D or 3-D arrays but with a variable number of columns in each row. These types of arrays are also known as Jagged arrays.

One-Dimensional (1D) Array

A 1D array is a list of elements stored in a single row. It is used to store multiple values of the same type in a linear format.

Syntax:


dataType[] arrayName = new dataType[size];

or


dataType[] arrayName = {value1, value2, value3, ...};

Example:

A list of students in a single class.


class MasterBackend {
    public static void main(String[] args) {
        // 1D Array: Students in a single class
        String[] students = {"Ayush", "Rahul", "Neha", "Priya"};

        System.out.println("Students in a class:");
        for (String student : students) {
            System.out.println(student);
        }
    }
}

Output:


Students in a class:
Ayush
Rahul
Neha
Priya

Whenever you're ready

There are 4 ways we can help you become a great backend engineer:

The MB Platform

Join 1000+ backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learnings and set schedules, and solve backend engineering tasks, exercises, and challenges.

The MB Academy

The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.

Join Backend Weekly

If you like post like this, you will absolutely enjoy our exclusive weekly newsletter, Sharing exclusive backend engineering resources to help you become a great Backend Engineer.

Get Backend Jobs

Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board