Storing file content into an array

前端 未结 2 422
别跟我提以往
别跟我提以往 2021-01-29 00:12

I\'m having a problem with my hangman program. I really think what I need to do is beyond what I understand about java. Here\'s my code

import java.io.BufferedRe         


        
相关标签:
2条回答
  • 2021-01-29 01:01

    You need to save the read line in a String object and assign it to a certain field of the array. For example:

    wordList[0] = myString;
    

    This would assign the value of myString to the first field of your array.

    0 讨论(0)
  • 2021-01-29 01:11

    1) What you've got so far looks pretty good :)

    2) Since you don't know exactly how many or few words you'll have, you don't want an "array". You're probably better off with an "ArrayList". Arrays are "fixed". Lists are "variable".

    3) For each "word" you read, just ".add()" it to your arraylist

    Voila! Done.

    Here's a complete example:

    • http://www.daniweb.com/software-development/java/threads/311569/readingwriting-arraylist-fromto-file#
    0 讨论(0)
提交回复
热议问题