How to initialize an array in Java?

后端 未结 10 2073
天命终不由人
天命终不由人 2020-11-22 00:23

I am initializing an array like this:

public class Array {

    int data[] = new int[10]; 
    /** Creates a new instance of Array */
    public Array() {
           


        
10条回答
  •  伪装坚强ぢ
    2020-11-22 01:11

    You cannot initialize an array like that. In addition to what others have suggested, you can do :

    data[0] = 10;
    data[1] = 20;
    ...
    data[9] = 91;
    

提交回复
热议问题