Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

import java.util.*;

public class Demo25
{
    public static void main(String[] args)
    {
        List<String> a = Arrays.asList("x", "y");
        List<String> b = Arrays.asList("y", "x");
        System.out.println(a.equals(b));
    }
}

  • A.The program prints false
  • B.The order is unspecified.
  • C.Compilation fails.
  • D.The program prints true

Answer: A

List equality is defined by order as well as contents: two lists are equal only when the elements at each position match. Reversing them therefore makes the lists unequal. A Set comparison of the same two collections would have been true, since a Set has no positions.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.