ProgrammingHardProduct-company placement · Java
What is printed?
What is printed?
Stream.of(1, 2, 3).peek(System.out::print).map(x -> x * 2);
System.out.print("end");- A. 123end
- B. 246end
- C. end
- D. 123246end
Correct answer: C. end
Intermediate operations such as peek and map do nothing until a terminal operation (forEach, collect, count…) runs. This pipeline has none, so peek's action never executes.
More OOP with C++ and Java questions
- What is printed? java Map<Integer, Long> m = Stream.of("a", "bb", "cc", "ddd", "e") .collect(Collectors.groupingBy(String::length…
- What is printed? java Map<Integer, String> m = Stream.of("ab", "cd", "e") .collect(Collectors.toMap(String::length, s -> s))…
- Why is the comparator (a, b) -> a - b unsafe for sorting arbitrary int values in Java?
- What is printed? java String s = "ab"; StringBuilder sb = new StringBuilder("ab"); System.out.print(s.equals(sb) + " " +…
- What happens when this class is compiled? java class Code implements Comparable<String>, Comparable<Integer> { public int compareTo(String…
- Which statement about Java anonymous classes is correct?