Menu
Question Index
...

Write a program to get the previous 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 15
[412, 410, 402, 404, 405, 406, 409, 411], 412 411
[10, 20, 26, 22, 90, 11, 15], 91 90
[7, 2, 8, 3, 1, 4, 5, 6], 0 null
null null


import java.util.*;
class GetPreviousElement
{
    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 previous element is : " + getPreviousElement(input, 4));

    }


    public static Integer getPreviousElement(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