Wow, this is bad. Hard coding data in your program is never a good idea in the first place. Hard coding a ton of data is no better, and you are faced with the limitations described in other answers.
There are several ways to fix this, but the following should not violate any other code.
public static String[] getTheArrayThing(){ List<String> list = new LinkedList<String>(); try { BufferedReader br = new BufferedReader(new FileReader(<the file>)); String line = br.readLine(); while (line != null) { list.add(line); line = br.readLine(); } } catch (Exception e){ throw new IllegalStateException("Couldn't load array file"); } return list.toArray(new String[0]); }
Basically, the method creates (and returns, but can just as easily edit the class variable) an array that contains each line of the file in order.
Just upload the values ββin the original example (for example, "newyorkartworld") to a text file - in order - and use this to load the array.
While this simple substitution will work, there is a much more elegant solution if you can take the time to do a little refactoring.
Kris Mar 09 2018-10-09T00: 00Z
source share