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]))) { while(sc.hasNext()) { String word = sc.next().toLowerCase(); wordsList.add(word); } Iterator it = wordsList.iterator(); while(it.hasNext()) System.out.print(it.next()+" "); System.out.println(""); } catch(FileNotFoundException ex) { System.out.println("Unable to open file \""+args[0]+"\""); } } }