← Java 처음부터
레슨 66 / 88 · 5 XP
워밍업: ArrayList 워밍업
이론과 문제
기계 번역이에요. 아직 원어민이 검토하지 않았어요.
ArrayList는 스스로 자라는 목록이에요. add는 끝에 붙이고, size()는 원소 개수를, get(0)은 첫 번째를 줘요:
ArrayList<String> words = new ArrayList<>();
while (in.hasNext()) { // 입력에 단어가 있는 동안
words.add(in.next());
}
System.out.println(words.size());
System.out.println(words.get(0));
과제. 입력이 끝날 때까지 모든 단어를 ArrayList에 읽고, 몇 개인지와 첫 단어를 두 줄에 출력하세요.