Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class Printer {
    public static void main(String args[]) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(25);    list.add(30);
        list.add(35);    list.add(40);
        list.add(45);
        Set<Integer> s = new TreeSet<Integer>();
        s.add(20);    s.add(35);
        s.add(55);    s.add(35);
        s.add(45);
        for (int i = 0; i < list.size(); i++) {
            if (!s.add(list.get(i)))
                System.out.print(list.get(i) + ",");
        }
        System.out.println("\n" + s);
    }
}


35,45,
[20, 35, 55, 45, 25, 30, 40]
35,45,
[20, 25, 30, 35, 40, 45, 55]
20,25,30,35,40,45,55
[35, 45]
Some other output
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