A, B, C, and D: Suppose that nameList is a list that contains the following stri
ID: 3718946 • Letter: A
Question
A, B, C, and D: Suppose that nameList is a list that contains the following strings: Kyle, Cathy, Sam, Austirn Sara. What output is produced by the following sequence of statements? Explain. A. --2 points C. -2 points -- Iterator namelterator nameList.iterator); System.out.println(namelterator.next(); namelterator.next(); System.out.println (namelterator.next)); namelterator.remove(); System.out.println(namelterator.next(); System.out.println (nameList); Listiterator namelterator = namelist.listiterator(); System.out.println(namelterator.next(); namelterator.next(); namelterator.next(); System.out.println(namelterator.next()); namelterator.set("Brittany"); namelterator.previous(); namelterator.remove(); System.out.println(namelterator.next()); System.out.println(nameList); B. -- 2 points -- Iterator namelterator nameList.iterator); namelterator.next(); namelterator.remove(); namelterator.next(); namelterator.next0; namelterator.remove(); System.out.println(namelterator.next()); System.out.println (nameList); System.out.println (namelterator.next)); System.out.println (namelterator.next()); D. -2 points ListiteratorExplanation / Answer
List contains Kyle, Cathy Sam Austin and Sara
A.
Iterator : Kyle (Prints Kyle)
Iterator : Cathy
Iterator : Sam (Prints Sam)
Removes Sam
Iterator : Austin (Printa Austin)
List is Kyle, Cathy, Austin, Sara
OUTPUT :
Kyle
Sam
Austin
[Kyle, Cathy, Austin, Sara]
B.
OUTPUT :
Austin
[Cathy, Austin, Sara]
Sara
Exception in thread "main" java.util.NoSuchElementException
at java.util.ArrayList$Itr.next(ArrayList.java:854)
at Main.main(GUI.java:26)
We get NoSuchElementException
C.
List Iterator moves in both forward and backward direction. Output is
OUTPUT :
Kyle
Austin
Sara
[Kyle, Cathy, Sam, Sara]
D.
OUTPTU :
Austin
Revised list:
[Cathy, Austin, Brittany]
Brittany
Brittany
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.