1Z0-805 · Question #41
Given: import java.util.*; public class StringApp { public static void main (String [] args) { Set <String> set = new TreeSet <> (); set.add("X"); set.add("Y"); set.add("X"); set.add("Y")…
The correct answer is D. X Y. A set is a collection that contains no duplicate elements. So set will include only two elements at the start of while loop. The while loop will execute once for each element. Each element will be Oracle 1Z0-805 Exam *public interface Iterator An iterator over a collection…
Question
Given:
import java.util.*; public class StringApp { public static void main (String [] args) { Set <String> set = new TreeSet <> (); set.add("X"); set.add("Y"); set.add("X"); set.add("Y"); set.add("X"); Iterator <String> it = set.iterator (); int count = 0; while (it.hasNext()) { switch (it.next()){ case "X":
System.out.print("X "); break; case "Y":
System.out.print("Y "); break; } count++; } System.out.println ("\ncount = " + count); } } What is the result?
Options
- AX X Y X Y
- BX Y X Y
- CX Y
- DX Y
How the community answered
(46 responses)- A9% (4)
- B15% (7)
- C4% (2)
- D72% (33)
Explanation
A set is a collection that contains no duplicate elements. So set will include only two elements at the start of while loop. The while loop will execute once for each element. Each element will be Oracle 1Z0-805 Exam *public interface Iterator An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways: Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. Method names have been improved. public boolean hasNext() Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.) publicObjectnext() Returns the next element in the iteration.
Topics
Community Discussion
No community discussion yet for this question.