data[10] = {10,20,30,40,50,60,71,80,90,91};

The above is not correct (syntax error). It means you are assigning an array to data[10] which can hold just an element.

If you want to initialize an array, try using Array Initializer:

int[] data = {10,20,30,40,50,60,71,80,90,91};

// or

int[] data;
data = new int[] {10,20,30,40,50,60,71,80,90,91};

Notice the difference between the two declarations. When assigning a new array to a declared variable, new must be used.

Even if you correct the syntax, accessing data[10] is still incorrect (You can only access data[0] to data[9] because index of arrays in Java is 0-based). Accessing data[10] will throw an ArrayIndexOutOfBoundsException.

Answer from Prasoon Saurav on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › arrays-in-java
Arrays in Java - GeeksforGeeks
You can use array literals to initialize an array when declaring it. In this case, the new keyword is not required- ... The length of this array determines the length of the created array.
Published   May 8, 2026
🌐
W3Schools
w3schools.com › java › java_arrays.asp
Java Arrays
Java Examples Java Videos Java ... of declaring separate variables for each value. To declare an array, define the variable type with square brackets [ ] :...
🌐
Baeldung
baeldung.com › home › java › java array › initializing arrays in java
Initializing Arrays in Java | Baeldung
December 16, 2024 - Additionally, when using the var keyword for type inference, we cannot initialize an array literal without the new keyword: ... The code above results in a compilation error. To use the var keyword with array literals, we must introduce the new keyword, allowing the compiler to infer the type from the right-hand side of the assignment: ... Here, the compiler can infer it’s an array of integers. The java.util.Arrays class has several methods named fill() that accept different types of arguments and fill the whole array with the same value:
🌐
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
class Main { public static void main(String[] args) { // declare the variable and allocate memory int[] myArray = new int[]{1, 2, 3}; for (int i = 0; i < 3; i++) { System.out.println(myArray[i]); } } } ... If you don’t want to hard code the ...
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › ArrayBasics › abasics.html
8.1. Arrays in Java — AP CSA Java Review - Obsolete
To create an array use the new keyword, followed by a space, then the type, and then in square brackets the size of the array (the number of elements it can hold). ... Array elements are initialized to 0 if they are a numeric type (int or double), false if they are of type boolean, or null ...
🌐
Opensource.com
opensource.com › article › 19 › 10 › initializing-arrays-java
Initializing arrays in Java | Opensource.com
October 22, 2019 - The int[] to the extreme left declares the type of the variable as an array (denoted by the []) of int. To the right is the name of the variable, which in this case is ia. Next, the = tells us that the variable defined on the left side is set to what’s to the right side. To the right of the = we see the word new, which in Java indicates that an object is being initialized, meaning that storage is allocated and its constructor is called (see here for more information).
Find elsewhere
🌐
HappyCoders.eu
happycoders.eu › java › initialize-array-java
How to Initialize Arrays in Java
June 12, 2025 - As with one-dimensional arrays, all Java style guides prefer the first variant. A two-dimensional array can be initialized directly in the declaration – with new followed by the type and two pairs of square brackets:
🌐
Sentry
sentry.io › sentry answers › java › how to initialize an array in java?
How to initialize an array in Java? | Sentry
October 21, 2022 - In Java, the array object is used to store multiple elements of the same type. These elements are stored in contiguous memory, the length of which is immutable once initialization is complete. We can declare an array in the same way as any other variable or object in Java, by giving a type and a name:
🌐
TutorialsPoint
tutorialspoint.com › javaexamples › array_fill.htm
How to fill (initialize at once) an array in Java
This example fill (initialize all the elements of the array in one short) an array by using Array.fill(arrayname,value) method and Array.fill(arrayname ,starting index ,ending index ,value) method of Java Util class.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › arrays.html
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
For instance, the ArrayCopyDemo example uses the arraycopy method of the System class instead of manually iterating through the elements of the source array and placing each one into the destination array. This is performed behind the scenes, enabling the developer to use just one line of code to call the method. For your convenience, Java SE provides several methods for performing array manipulations (common tasks, such as copying, sorting and searching arrays) in the java.util.Arrays class.
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Initializing an Array | Study.com
To reference a bucket in the array you need to provide its index. Remember, Java starts counting at zero! Therefore, the first bucket will have an index of 0. Right now all buckets are zero. So, if we printed the following, the FOURTH bucket in highScores: ... Now that we've covered the general way to initialize an array, let's look at some more options.
🌐
Coderanch
coderanch.com › t › 656499 › java › ways-initialize-array
Different ways to initialize an array (Beginning Java forum at Coderanch)
October 12, 2015 - Campbell Ritchie wrote:The difference between the first and second methods in OP's post are that one creates an array with elements and the other an empty array. You can see that so much better with arrays of reference types than of primitives. If you have code like this (from this post):-If you print that out with methods of the Arrays class you get the obvious output:-What you have here is a declaration and array initialiser later.
🌐
Pluralsight
pluralsight.com › blog › software development
How to initialize an array in Java | Pluralsight
When you make an array in Java for the first time, you’ve got to declare its size. This is because the array’s size is fixed from the moment you create it. The simplest way to do this is to initialize an empty array of a declared size.
🌐
BeginnersBook
beginnersbook.com › 2024 › 06 › java-array-declaration-and-initialization
Java Array Declaration and Initialization
June 3, 2024 - Initialization: arrayName[index] = value; or type[] arrayName = {value1, value2, ...}; For example: numbers[0] = 1; or numbers = {1, 2, 3, 4, 5}; ... I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade ...
🌐
Software Testing Help
softwaretestinghelp.com › home › java tutorial for beginners: 100+ hands-on java video tutorials › java array – declare, create & initialize an array in java
Java Array - Declare, Create & Initialize An Array In Java
April 1, 2025 - Each element ‘i’ of the array is initialized with value = i+1. Apart from using the above method to initialize arrays, you can also make use of some of the methods of ‘Arrays’ class of ‘java.util’ package to provide initial values for the array. We will discuss some of these methods below. The fill() method of the ‘Arrays’ class can be used to initialize the array. When you initialize an array using this method, the array is filled with the same values at all indices.
🌐
Scaler
scaler.com › home › topics › check and declare empty array in java
Check and Declare Empty Array in Java - Scaler Topics
November 16, 2023 - To initialize an empty array java we need to use the new keyword followed by the data type of the elements the array would store.
🌐
JanBask Training
janbasktraining.com › community › java › how-do-i-declare-and-initialize-an-array-in-java
How do I declare and initialize an array in Java? | JanBask Training Community
May 21, 2025 - To declare an array in Java, you specify the type of elements it will hold, followed by square brackets. ... This line declares an array of integers but doesn’t allocate memory yet. ... If you know how many elements the array will hold but not their values yet, you can initialize it with a fixed size.
🌐
Quora
quora.com › How-do-I-initialize-an-array-in-Java
How to initialize an array in Java - Quora
For example, if you want to initialize an int array: ... Note that size must be a positive integer. If you already know the data you want to store, you can write it out manually like so: ... You can make an array for any primitive values or objects. For example, a String is a type of object in Java ...
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
Elements in an ArrayList are actually objects. In the examples above, we created elements (objects) of type "String". Remember that a String in Java is an object (not a primitive type). To use other types, such as int, you must specify an equivalent wrapper class: Integer.