Menu
Topics Index
...
`

Creating TreeSet


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating TreeSet
What will be the output of the following program?
import java.util.*;
public class Freq {
    public static void main(String args[]) {
        TreeSet str = new TreeSet();
        for (int key = 1; key < 4; key++)
            for (int value = 1; value < 4; value++)
                ((Map) str).put((key * key - key), value);
        System.out.println(str);
    }
}

A. [1, 2, 3]
B. [0, 2, 6]
C. {0=3, 2=3, 6=3}
D. Some other output
E. Compilation Error or Runtime Error
Topic: Collection Framework In Java

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 B..the values in the map corresponding to the value are printed..1*1-1=0,2*2-2=2,3*3-3=6

Posted by Badam Swathi    2014-07-22 03:40:00


Ans is E
because we cannot cast a TreeSet into Map.. so we will get ClassCastException

Posted by Gopinath Manchikanti    2014-07-22 04:29:20


ans B because of 1*1-1=0,2*2-2=2,3*3-3=6......

Posted by Vishnu Vardhan Reddy    2014-07-22 05:28:34


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-07-23 04:16:45


© meritcampus 2019

All Rights Reserved.

Open In App