Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me how I can able to intialize an array? I was trying to do it using the below code:

public class Array {

    int data[] = new int[10]; 

    /** Creates a new instance of Array */

    public Array() {

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

    }     

}

It is throwing an error. Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

Basically, the above format is not correct, it contains a syntax error. You can try using Array Initializer like this:

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

That will help you to initialize properly.

I hope this will help.

Want to become a Java expert? join Java Training now!!

Related questions

0 votes
1 answer
asked Mar 11, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 12, 2021 in Java by Jake (7k points)
0 votes
1 answer

Browse Categories

...