Home » JAVA Programming » Data Structures » Question
  1. What is the output of below code snippet?
    import java.util.*;
    public class HashSet_Example
    {
    public static void main(String[] args)
    {
    Set setobj = new HashSet();
    setobj.add(new Long(20));
    setobj.add(new Integer(30));
    for(Object object : setobj)
    {
    System.out.println("test - "+object);
    }
    }
    }
    1. test - 20
    2. test - 30
    3. test - 20
      test - 30
    4. test
    5. None of these
Correct Option: C

Integer and Long are two different data types and different objects. So they will be treated as unique elements and not overridden.



Your comments will be displayed only after manual approval.