Return to site
JAVA CERTIFICATION QUESTION: HashSet and TreeSet sources in Java streams
=>Sometimes you must pay attention to the encounter order of elements in a stream.
·
Given:
List<String> wordList = Arrays.asList("how", "this", "may", "be", "correct"); Set<String> words1 = new HashSet<>(wordList); Set<String> words2 = new TreeSet<>(wordList); // CODE OMITTED HERE System.out.print(words1.stream().findFirst().get()); System.out.println(words2.stream().findFirst().get());
Assume that the behavior of the code not shown at the // CODE OMITTED HERE line is to add more elements to both setsand then delete all the newly added elements.
As a result, the number and values of the data items in the sets after this comment are identical to the contents before this line.
Which best describes the possible output? Choose one.
A. bebe
B.
be <any value from list>
C.
<any value from list>be
D.
<any value from list><any value from list>
·ꓛ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ