Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class HashSet_Example
    {
    public static void main(String args[])
    {
    HashSet object = new HashSet();
    object.add("I");
    object.add("L");
    object.add("U");
    System.out.println(object + " " + object.size());
    }
    }
    1. [U, I, L]
    2. [I, L, U] 3
    3. [I, L, U]
    4. [U, I, L] 3
    5. None of these
Correct Option: D

HashSet obj creates an hash object which implements Set interface, object.size() gives the number of elements stored in the object object which in this case is 3.



Your comments will be displayed only after manual approval.