Menu
Topics Index
...
`

LastEntry


If you need explanation Read this topic

If you need Answer Take test on this topic

LastEntry
What will be the output of the following program?
import java.util.*;
public class LastEntry {
    public static void main(String args[]) {
        NavigableMap<Integer, Integer> last = new TreeMap<Integer, Integer>();
        last.put(5, 11);
        last.put(28, 29);
        last.put(5, 27);
        System.out.println(last.lastEntry());
        System.out.print(last.lowerEntry(5));
    }
}

A. 5=27
null
B. 28=29
5=11
C. 5=27
5=11
D. 28=29
null
E. CompilationError or Runtime Error
Topic: TreeMap In Java - java.util.TreeMap

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: C

Posted by Vinay Jogu    2014-03-25 13:06:10


lastentry() function returns ...last entry..5,27
lower entry (5)..here 5 denotes key value
there no value less then 5 ...so returns null
ans : a

Posted by Ananda Kumar    2014-03-25 13:14:06


Ans is D since A NavigableMap may be accessed and traversed in either ascending or descending key order. The descendingMap method returns a view of the map with the senses of all relational and directional methods inverted.

Posted by Naga Sinst    2014-03-25 14:38:53


The lastEntry() method returns an entry (key-value mapping) with the greatest key. Thus we get 28=29 in this case. The lowerEntry() method returns an entry (key-value mapping) with the greatest key less than the key passed in as parameter. It returns null if it doesn't find any such key. Therefore, we get null in this case. So, the answer is D.

Posted by Shaileshwar Sharma    2014-03-25 15:05:43


Congratulations Shaileshwar Sharma. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-26 04:45:32


© meritcampus 2019

All Rights Reserved.

Open In App