Menu
Topics Index
...
`

Collections2041


If you need explanation Read this topic

If you need Answer Take test on this topic

Collections2041
What will be the output of following program?
import java.util.*;

public class Singletons {
    public static void main(String[] args) {
        Set<Double> doubleSet = Collections.singleton(23.5);
        List<Double> doubleList = Collections.singletonList(23.5);
        Map<Double, Double> doubleMap = Collections.singletonMap(23.5, 23.5);
        System.out.print(doubleSet.containsAll(doubleList) + "#");
        doubleSet.removeAll(doubleList);
        System.out.print(doubleSet.containsAll(doubleList) + "#");
        doubleList.addAll(doubleMap.keySet());
        System.out.print(doubleSet.containsAll(doubleList) + "#");
    }
}

A. true#false#true
B. true#true#true
C. false#false#false
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java Singleton

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 is E. Exception arises after printing true for the first println statement. the removeAll() method throws an exception because the operation can not be performed or unsupported

Posted by Nikhil Sulibhavi    2014-06-05 12:53:09


ans e. prints true# aft tis removeall() line throws exception bcz it is unsupportedoperation

Posted by Maheshwari Natarajan    2014-06-05 12:57:49


Answer : E RunTimeException
As we cannot perform the removeAll() , doubleList.addAll() operation on this as they are unsupportedOperations

Posted by Deepak Kumar Yadav    2014-06-05 15:02:08


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

Posted by Merit Campus    2014-06-06 04:21:30


© meritcampus 2019

All Rights Reserved.

Open In App