Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 12

Given the code fragment:

What is the result?

    Correct Answer: C

    The code creates two maps based on the symbols and exchange rates provided. The first map (map1) converts the symbols to an exchange rate as a reciprocal value and does not preserve any specific order. The second map (map2) sorts these entries by the natural order of the keys (symbol strings) and collects them into a LinkedHashMap, which maintains this order during iteration. The final output reflects this sorted order: CNY -> 6.42, EUR -> 0.84, GBP -> 0.75, USD -> 1.00.

Discussion
pikosssOption: C

C is Correct

RP384Option: C

This compiles fine

RP384Option: C

Correct answer: C

Bugmenot240411Option: C

C is the correct answer

d7bb0b2Option: C

C is correct 1- first map not considered order. (stream) {EUR=0.8354916868577157, GBP=0.7544322897019993, USD=1.0, CNY=6.418098009491084} 2- second map sorted by natural order of the key and uses linkedhash, then output format values to two decimal CNY -> 6.42 EUR -> 0.84 GBP -> 0.75 USD -> 1.00

d7bb0b2

notice: value is not important in this case, only key

duydnOption: C

class Test { public static void main(String[] args) throws IOException { var symbols = List.of("USD", "GBP", "EUR", "CNY"); var exchangeRate = List.of(1.0, 1.3255, 1.1969, 0.1558094); var map1 = IntStream.range(0, Math.min(symbols.size(), exchangeRate.size())).boxed() .collect(Collectors.toMap(i -> symbols.get(i), i-> 1.0 / exchangeRate.get(i))); var map2 = map1.entrySet().stream() .sorted(Map.Entry.comparingByKey()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new)); map2.forEach((var k, var v) -> System.out.printf("%s -> %.2f\n", k, v)); } } -> C

ue02765Option: C

run: CNY -> 6,42 EUR -> 0,84 GBP -> 0,75 USD -> 1,00 BUILD SUCCESSFUL (total time: 0 seconds)

StavokOption: C

C is correct