Java File into ArrayList and referencing the ArrayList to another class -
so have been coding project in java , have come across pause while trying reference array list class. first bit of code class trying reference arraylist
too. second creating arraylist
s.
import game.app; public class wordpuzzlegenerator { public wordpuzzlegenerator() { if (game.sizeofpuzzle.currentrows == 4){ threeletterwordlist }else if (game.sizeofpuzzle.currentrows == 5){ maximum = 12482; }else{ maximum = 1310; } }
scanner threeletterscanner = new scanner(file("3letterwords.txt")); arraylist<string> threeletterwordlist = new arraylist<string>(); while (threeletterscanner.hasnext()){ threeletterwordlist.add(threeletterscanner.next()); } threeletterscanner.close(); scanner fourletterscanner = new scanner(file("4letterwords.txt")); arraylist<string> fourletterwordlist = new arraylist<string>(); while (fourletterscanner.hasnext()){ fourletterwordlist.add(fourletterscanner.next()); } fourletterscanner.close(); scanner fiveletterscanner = new scanner(file("5letterwords.txt")); arraylist<string> fiveletterwordlist = new arraylist<string>(); while (fiveletterscanner.hasnext()){ fiveletterwordlist.add(fiveletterscanner.next()); } fiveletterscanner.close(); }
use variable inside class like:
public class wordpuzzlegenerator { arraylist<string> threeletterwordlist = new arraylist<string>(); //... public list<string> getthreeletterwordlist() { return threeletterwordlist ; } }
then can call mygenerator.getthreeletterwordlist(); list.
Comments
Post a Comment