import java.util.ArrayList; ArrayList<String> words= new ArrayList<>(); while (x.hasNext()) { String a = x.next(); words.add(a); }