import java.util.*; import java.io.*; public class ListExample { public static void main(String []args) { List wordsList = new ArrayList<>(); try(Scanner sc = new Scanner(new File(args[0]))) { ListIterator it = wordsList.listIterator(); while(sc.hasNext()) { String word = sc.next().toLowerCase(); it.add(word); } it = wordsList.listIterator(wordsList.size()); while(it.hasPrevious()) System.out.print(it.previous()+" "); System.out.println(""); } catch(FileNotFoundException ex) { System.out.println("Unable to open file \""+args[0]+"\""); } } }