Adding integers to an int array

前端 未结 7 978
我在风中等你
我在风中等你 2021-02-05 01:57

I am trying to add integers into an int array, but Eclipse says:

cannot invoke add(int) on the array type int[]

Which is completely

7条回答
  •  青春惊慌失措
    2021-02-05 02:19

    Arrays are different than ArrayLists, on which you could call add. You'll need an index first. Declare i before the for loop. Then you can use an array access expression to assign the element to the array.

    num[i] = s;
    i++;
    

提交回复
热议问题