I am writing a method that receives a file and returns an array list with every other word from the file. The files can contain multiple lines.
For example, if I scan through the File and it reads
{"red", "orange", "yellow", "green", "blue", "purple"} The method should return the list
{"red","yellow","blue"} I'm aware this is a rather simple question and if it has already been answered, please point me in the right direction. Also, I believe these are comma separated variables. So far I have my header and scanner declaration:
public static ArrayList<String>Skip(File file) ArrayList<String> newList = new ArrayList<String>(); Scanner scanner = new scanner(file); while(scanner.hasNextLine()){ *WHAT DO I DO HERE* newList.add(____); } scanner.close; } return newList;
booleanvariableaddThisWordthat tells you whether you're going to add the word or not. Then after you see a word,addThisWord = !addThisWord;will cause it to flip back and forth betweentrueandfalse.