Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default higher() method of NavigableSet

    From the complete reference java book on the topic NavigableSet:

    E higher(E obj): Searches the set for the largest element e such that e>obj. If such an element is found, it is returned. Otherwise, null is returned
    Java Code:
    import java.util.*;
    
    public class TreeSetDemo
    {
    	public static void main(String arg[])
    	{
    		TreeSet t=new TreeSet();
    		
    		t.add(new Integer(20));
    		t.add(new Integer(10));
    		t.add(new Integer(30));
    		t.add(new Integer(100));
    		System.out.println(t.higher(25));
    		
    	}
    }
    According to the statement the output should be 100(largest element) but the output is 30. Someone clarify who is wrong?

  2. #2
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    720
    Rep Power
    2

    Default Re: higher() method of NavigableSet

    Returns the least element in this set strictly greater than the given element, or null if there is no such element.
    The JavaDoc talks about the LEAST higher, not the HIGHEST. The wording in the book was chosen awkward, but it says e > obj, so I would choose to say: "the smallest element where e > obj".

  3. #3
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Re: higher() method of NavigableSet

    Yes, look likes the author used largest element where he should have used the smallest element which satisifies the condition

Similar Threads

  1. Replies: 7
    Last Post: 04-11-2013, 05:31 AM
  2. Replies: 2
    Last Post: 03-23-2012, 04:53 AM
  3. Replies: 1
    Last Post: 10-17-2011, 01:00 AM
  4. how to call higher level super class method?
    By satheeshtech in forum Advanced Java
    Replies: 2
    Last Post: 01-12-2010, 03:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •