Menu
Topics Index
...
`

Creating Set


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Set
What will the output of the following program?
import java.util.*;
public class SetTest{
    public static void main(String arg[]){
        Set s = new HashSet();
        s.add("A");
        s.add("B");
        s.add("C");
        s.add("D");
        s.add("E");
        s.add("F");
        s.add("H");
        Collections.unmodifiableSet(s);
        s = Collections.unmodifiableSet(s);
        s.clear();
        System.out.println(s);
    }
}

A. [D, E, F, A, B, C, H]
B. [A, B, C, D, E, F, G]
C. [H, F, E, D, C, B, A]
D. Compilation Error
E. Throws Exception
Topic: Java Read-only Collections And Algorithms

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans e as the obj s is assigned ti unmodifiableSet ..it throws an exception when a function clear is invoked on it.

Posted by Manasa Jyothi Sree    2014-06-19 03:36:06


Ans is E.
It will throw UnsupportedOperationException while using clear().

Posted by Gopinath Manchikanti    2014-06-19 03:42:58


Ans is e throws exception when function cleart is invoked

Posted by Bharath Yelchuri    2014-06-19 08:44:50


Congratulations Gopinath Manchikanti. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-20 04:33:27


© meritcampus 2019

All Rights Reserved.

Open In App