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

后端 未结 5 1419
小蘑菇
小蘑菇 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条回答
  •  走了就别回头了
    2021-01-29 11:53

    Arrays in java have a static number of slots. You have to know the number you need at the time you instanciate the array.

    What you want is either:

    array[count] = element;
    

    or you can use a List (e.g. ArrayList, since List is just an interface)

提交回复
热议问题