Adding to the Sandeep Kakote's answer :

 public static void main(String[] args) {
            // TODO Auto-generated method stub
            double[] squareArry = powArray(new double[]{10,20,30},3);

        }

        public static double[] powArray (double a[],int z){
            double[] b = new double[a.length];
            for (int i = 0; i < a.length; i++) {
                b[i] = Math.pow(a[i], z);
                System.out.print(b[i]);
            }
            return b;
        }
Answer from Sourav Sachdeva on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_arrays.asp
Java Arrays
Java Examples Java Videos Java ... Q&A Java Certificate ... Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value....
Discussions

Creating an array method java - Stack Overflow
Here I need to write a method called powArray that takes a double array a and returns a new array that contains the elements of a squared. Generalize it to take a second argument and raise the elem... More on stackoverflow.com
🌐 stackoverflow.com
How do I declare and initialize an array in Java? - Stack Overflow
Both the outer arrays and the inner arrays (and those in between, if they exist) are just regular arrays. 2017-07-18T15:19:10.57Z+00:00 ... Perhaps worth noting that the second (less-preferred) form stems from C/C++. This might be the reason why it is supported in Java. More on stackoverflow.com
🌐 stackoverflow.com
How to make an array of arrays in Java - Stack Overflow
What I have done is a small utility class Array2D which encapsulates some basic methods such as exixts(...) etc. I posted this below. 2012-11-29T13:54:33.883Z+00:00 ... there is the class I mentioned in the comment we had with Sean Patrick Floyd : I did it with a peculiar use which needs WeakReference, but you can change it by any object with ease. ... import java... More on stackoverflow.com
🌐 stackoverflow.com
Does Java ArrayList implement an array or list abstract data type?
An Abstract Data Type (ADT) tells you how a data structure should behave without worrying about how it is implemented. An ArrayList is an implementation of a List ADT. You can also have a LinkedList which is another implementation of a List ADT. The ADT does not care that the ArrayList is implemented with an array and LinkedList is implemented with linked nodes. In addition, there are two types of LinkedList that are the common types. Singly-linked and doubly linked. The List ADT does not care just that the behavior is the same to whomever is using these list implementations. For instance, the List ADT might say the add method adds to the end of the list if no index is specified. So, whether you write an ArrayList or LinkedList when you write the add method with no index specified the item should be added to the end. How you do that is up to you. More on reddit.com
🌐 r/learnprogramming
4
2
December 10, 2021
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Arrays.html
Arrays (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... This class contains various methods for manipulating arrays (such as sorting and searching).
🌐
University of San Francisco
cs.usfca.edu › ~galles › visualization › Algorithms.html
Data Structure Visualization
Lists: Array Implementation (available in java version) Lists: Linked List Implementation (available in java version) Recursion · Factorial · Reversing a String · N-Queens Problem · Indexing · Binary and Linear Search (of sorted list) Binary Search Trees ·
🌐
Princeton CS
introcs.cs.princeton.edu › java › 14array
Arrays
April 8, 2020 - To access each of the elements in a two-dimensional array, we need nested loops: Memory representation. Java represents a two-dimensional array as an array of arrays. A matrix with m rows and n columns is actually an array of length m, each entry of which is an array of length n.
🌐
Croma Campus
cromacampus.com › blogs › what-is-an-array-in-java
What is an Array in Java? Step-by-Step Guide
An array in Java is a data structure that stores multiple values of the same type in a single variable, allowing efficient data storage and access by index.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › arrays-in-java
Arrays in Java - GeeksforGeeks
An array is a collection of elements of the same data type stored in contiguous memory locations. It allows multiple values to be stored under a single name and accessed using an index.
Published   2 weeks ago
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › reflect › Array.html
Array (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The Array class provides static methods to dynamically create and access Java arrays.
🌐
Igmguru
igmguru.com › blog › arrays-in-java
Arrays in Java: Declare, Define, and Access Array
3 weeks ago - This Java Arrays tutorial explains everything about Arrays in Java, from basic definition and pros and cons to how to declare of define, and access them.
Top answer
1 of 16
3263

You can either use array declaration or array literal (but only when you declare and affect the variable right away, array literals cannot be used for re-assigning an array).

For primitive types:

int[] myIntArray = new int[3]; // each element of the array is initialised to 0
int[] myIntArray = {1, 2, 3};
int[] myIntArray = new int[]{1, 2, 3};

// Since Java 8. Doc of IntStream: https://docs.oracle.com/javase/8/docs/api/java/util/stream/IntStream.html

int [] myIntArray = IntStream.range(0, 100).toArray(); // From 0 to 99
int [] myIntArray = IntStream.rangeClosed(0, 100).toArray(); // From 0 to 100
int [] myIntArray = IntStream.of(12,25,36,85,28,96,47).toArray(); // The order is preserved.
int [] myIntArray = IntStream.of(12,25,36,85,28,96,47).sorted().toArray(); // Sort 

For classes, for example String, it's the same:

String[] myStringArray = new String[3]; // each element is initialised to null
String[] myStringArray = {"a", "b", "c"};
String[] myStringArray = new String[]{"a", "b", "c"};

The third way of initializing is useful when you declare an array first and then initialize it, pass an array as a function argument, or return an array. The explicit type is required.

String[] myStringArray;
myStringArray = new String[]{"a", "b", "c"};
2 of 16
336

There are two types of array.

One Dimensional Array

Syntax for default values:

int[] num = new int[5];

Or (less preferred)

int num[] = new int[5];

Syntax with values given (variable/field initialization):

int[] num = {1,2,3,4,5};

Or (less preferred)

int num[] = {1, 2, 3, 4, 5};

Note: For convenience int[] num is preferable because it clearly tells that you are talking here about array. Otherwise no difference. Not at all.

Multidimensional array

Declaration

int[][] num = new int[5][2];

Or

int num[][] = new int[5][2];

Or

int[] num[] = new int[5][2];

Initialization

 num[0][0]=1;
 num[0][1]=2;
 num[1][0]=1;
 num[1][1]=2;
 num[2][0]=1;
 num[2][1]=2;
 num[3][0]=1;
 num[3][1]=2;
 num[4][0]=1;
 num[4][1]=2;

Or

 int[][] num={ {1,2}, {1,2}, {1,2}, {1,2}, {1,2} };

Ragged Array (or Non-rectangular Array)

 int[][] num = new int[5][];
 num[0] = new int[1];
 num[1] = new int[5];
 num[2] = new int[2];
 num[3] = new int[3];

So here we are defining columns explicitly.
Another Way:

int[][] num={ {1}, {1,2}, {1,2,3,4,5}, {1,2}, {1,2,3} };

For Accessing:

for (int i=0; i<(num.length); i++ ) {
    for (int j=0;j<num[i].length;j++)
        System.out.println(num[i][j]);
}

Alternatively:

for (int[] a : num) {
  for (int i : a) {
    System.out.println(i);
  }
}

Ragged arrays are multidimensional arrays.
For explanation see multidimensional array detail at the official java tutorials

🌐
CodingBat
codingbat.com › java
CodingBat Java
Java Arrays and Loops · Java Map Introduction · Java Map WordCount · Java Functional Mapping · Java Functional Filtering · Code Badges ·
🌐
Scaler
scaler.com › home › topics › java › java arrays
Understanding Array in Java - Scaler Topics
April 8, 2024 - Arrays in Java can hold primitive data types (Integer, Character, Float, etc.) and non-primitive data types(Object). The values of primitive data types are stored in a memory location, whereas in the case of objects, it's stored in heap memory. Hence, it’s required to specify the data type while creating it.
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › java-array
Java Array: A Complete Guide With Examples
Arrays in Java are a fundamental data structure that allow you to store multiple values of the same type in a single variable. They provide a convenient way to manage and manipulate collections of data, whether you're dealing with numbers, strings, ...
🌐
Sentry
sentry.io › sentry answers › java › how do i declare and initialize an array in java?
How do I declare and initialize an array in Java? | Sentry
The easiest way to declare and initialize an array of a primitive type such as int in Java is by using the following syntax.
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-class-in-java
Arrays Class in Java - GeeksforGeeks
The Arrays class in the java.util package is a utility class that provides a collection of static methods for performing common operations on Java arrays, such as sorting, searching, comparing and converting arrays to strings.
Published   November 13, 2025
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... A multidimensional array is an array that contains other arrays.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-programming-interview-questions
Top Java Coding Interview Questions (With Answers) | DigitalOcean
April 17, 2025 - Whether you’re a beginner in Java or an expert programmer, this article provides some common Java interview questions and answers to help you prepare. There is no reverse() utility method in the String class. However, you can create a character array from the string and then iterate it from ...
🌐
CodeGym
codegym.cc › java blog › java arrays › java arrays
Java arrays with Examples
April 24, 2025 - An array is a data structure that stores elements of the same type. You can think of it as a set of numbered cells. You can put some data in each cell (one data element per cell).