title: How exactly NavigableMap.ceiling Entry() work?
body: <p>I don't understand how <code>NavigableMap.floorEntry()</code> and <code>ceiling Entry()</code> work.</p>
  
  <p>Oracle simply writes about <a href="https://docs.oracle.com/javase/8/docs/api/java/util/NavigableMap.html#ceilingEntry-K-" rel="nofollow noreferrer">ceilingEntry(key)</a>:</p>
  
  <blockquote>
    <p>Returns a <strong>key-value</strong> mapping associated with the <em>least key 
    <strong>greater than or equal to the given key</em></strong>, or <strong>null</strong> if there is no such
    key.</p>
  </blockquote>
  
  <p>Experimentally I learned that if I define <code>NavigableMap</code> with integer key (<code>NavigableMap&lt;Integer, Anything&gt;</code>), <code>floorEntry(keyArg)</code> and <code>ceilingEntry(keyArg)</code> always return the entry with given argument <code>(keyArg)*</code></p>
  
  <p>I understand that - it works like <a href="https://en.wikipedia.org/wiki/Floor_and_ceiling_functions" rel="nofollow noreferrer">floor and ceiling functions in math</a>: those functions <strong>return closest integer</strong> (if given not integer argument), given an <strong>integer argument</strong> they always <strong><em>return</em></strong> this <strong>given argument</strong>.</p>
  
  <p>I thought (<em>based on <strong>floor/entry</strong> definition in math</em>) that snippet below would return <code>"integer"</code> <code>1.0</code>, <code>2.0</code>, etc.</p>
  
  <p>Double <code>2.0</code> is not an integer. But <code>ceilingEntry(keyArg)</code> is of no use with Integer keys, if it also does not work with Double keys (also returning its argument key) then how is it used, what is the use of it and working use cases?</p>
  
  <pre><code>    NavigableMap&lt;Double, String&gt; m = new TreeMap&lt;&gt;();
      m.put(1.3, "hey");
      m.put(1.5, "hey2");
      m.put(1.62, "hey3"); // not this 
      m.put(1.6, "hey3");     // argument given to ceilingEntry
      m.put(1.68, "hey3"); // not this
      m.put(1.7, "hey4");  // not this
      m.put(2.0, "hey4");  // not this
      m.put(1.0, "hey4");
      m.put(3d, "hey4");   // not this
      m.put(0d, "hey4");
                           // WHAT THEN ???    
  
      System.out.println(m.ceilingEntry(1.6)); // OUTPUT: 1.6=hey3
  
      // I guess, to get something different from argument 
      //I shall give something not equal to any key as argument
  
      System.out.println(m.ceilingEntry(1.601)); // 1.62=hey3
  </code></pre>
  
  <p>I got it. Whatever the key type, if exactly such key is already present in the map, ceilingEntry would simply return its argument.</p>
  
  <p>It would return anything different only if the given argument is NOT present within map (as key). In this case ceilingEntry would return closest key in the map (in case of ceilingEntry - searching in ascending order (towards positive infinity)).</p>
  
  <p>So it is quite unlike pure math <code>floor/ceiling</code> - java is not looking for closest integer, java is looking for the closest existing key. Java does not care, whether this closest key is integer or <code>0.000786</code> (which is closest to arguments like <code>0.000785</code> or<code>0.7</code>)</p>