ProgrammingHardProduct-company placement · Java
What is printed?
What is printed?
List<Integer> a = new ArrayList<>(List.of(1, 2)); List<Integer> b = new LinkedList<>(List.of(1, 2)); System.out.print(a.equals(b) + " " + List.of(1, 2).equals(Set.of(1, 2)));
- A. true false
- B. false false
- C. true true
- D. false true
Correct answer: A. true false
List.equals is defined for any List with equal elements in the same order, whatever the implementation. A Set is never equal to a List.
More OOP with C++ and Java questions
- What is printed? java Queue<Integer> q = new ArrayDeque<>(); q.add(1); q.add(2); q.offer(3); q.poll(); System.out.print(q.peek() + " " +…
- What is printed? java System.out.print(Stream.of(1, 2, 3).reduce(10, Integer::sum));
- What is printed? java long n = Stream.of(List.of(1, 2), List.of(2, 3)) .flatMap(List::stream).distinct().count(); System.out.print(n);
- 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 ==…