error: cannot find symbol array.add(element);

后端 未结 5 1422
小蘑菇
小蘑菇 2021-01-29 11:34

I have a program that reads from a file, takes each word and adds it to an array as a String. I\'m having a bit of trouble with adding the Strings to the array. I get the e

5条回答
  •  梦毁少年i
    2021-01-29 11:52

    That's not how you add an element to Java array. Keep a counter outside the loop that will be incremented inside the loop block and then add elements like below:

    int i = 0;
    while(.....){
        .
        .
        array[i] = //element to be added
        i++;
    }
    

提交回复
热议问题