← Java from Scratch Lesson 66 of 88 · 5 XP

Warm-up: ArrayList warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

ArrayList is a list that grows by itself. add appends to the end, size() tells how many elements, get(0) is the first one:

ArrayList<String> words = new ArrayList<>();
while (in.hasNext()) {          // while there are words in the input
    words.add(in.next());
}
System.out.println(words.size());
System.out.println(words.get(0));

Task. Read all the words until the end of input into an ArrayList and print, on two lines, how many there are and the first word.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.