ProgrammingModerateProduct-company placement · Java
What is printed?
What is printed?
long n = Stream.of(List.of(1, 2), List.of(2, 3))
.flatMap(List::stream).distinct().count();
System.out.print(n);- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: B. 3
flatMap turns the two lists into one stream 1, 2, 2, 3; distinct removes the repeated 2, leaving 3 elements.
More OOP with C++ and Java questions
- What is printed? java Map<Boolean, List<Integer>> m = Stream.of(2, 4) .collect(Collectors.partitioningBy(x -> x > 5))…
- What happens? java interface Show { String toString(); } class C implements Show { } // in main: System.out.print(new C() instanceof Show);
- What is printed? java System.out.print((Double.NaN == Double.NaN) + " " + Double.valueOf(Double.NaN).equals(Double.NaN) + " " + (0.0 ==…
- A class overrides equals correctly, but its hashCode() returns 42 for every object. What happens when many such objects are stored in a…
- What happens? java class P { int v; P(int v) { this.v = v; } } // in main: Set<P> s = new TreeSet<>(); s.add(new P(1)); s.add(new P(2))…
- Which constructors cause compile-time errors? java class F { final int x; F() { } // constructor 1 F(int v) { x = v; x = v + 1; } //…