Menu
Question Index
...

What will be the output of following program?

import java.util.*;
public class Tree {
    public static void main(String[] args) {
        TreeSet<Integer> tree1 = new TreeSet<Integer>();
        TreeSet<Integer> tree2 = new TreeSet<Integer>();
        for (int i = 100; i < 150; i++)
            if (i % 7 == 0)
                tree1.add(i);
        tree2 = (TreeSet) tree1.subSet(126, false, 134, true);
        tree1.add(176);
        System.out.println(tree1 + " " + tree2);
    }
}


[105, 112, 119, 126, 133, 140, 147, 176] [133]
[105, 112, 119, 126, 133, 140, 147, 176] [134]
[105, 112, 119, 126, 133, 140, 147, 176] [126,134]
[105, 112, 119, 126, 133, 140, 147, 176] [125,133]
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java TreeSet - TreeSet Examples in Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App