Storing file content into an array

前端 未结 2 427
别跟我提以往
别跟我提以往 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: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#

提交回复
热议问题