Menu
Question Index
...

Write a program to get the next element from given inputs by using one of the TreeSet methods.
Note the elements in TreeSet by default sorted in ascending order.

Input (TreeSet, Integer) Output (Integer)
[15, 25, 99, 40, 10, 20, 30], 20 25
[7, 2, 8, 3, 1, 4, 5, 6], 0 1
[412, 410, 402, 404, 405, 406, 409, 411], 412 null
[10, 20, 26, 22, 90, 11, 15], 91 null
null null


import java.util.*;
class GetNextElement
{
    public static void main(String s[])
    {
        TreeSet input = new TreeSet();
        input.add(1);
        input.add(3);
        input.add(2);
        input.add(6);
        input.add(5);
        input.add(4);
        System.out.println("The next element is : " + getNextElement(input, 4));

    }


    public static Integer getNextElement(TreeSet input, Integer element) {
    }

}

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