Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the standard <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html#min%28java.util.Collection%29" rel="noreferrer"><code>Collections#min()</code></a> for this.</p> <pre><code>Map&lt;String, Double&gt; map = new HashMap&lt;String, Double&gt;(); map.put("1.1", 1.1); map.put("0.1", 0.1); map.put("2.1", 2.1); Double min = Collections.min(map.values()); System.out.println(min); // 0.1 </code></pre> <p><strong>Update</strong>: since you need the key as well, well, I don't see ways in <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html" rel="noreferrer"><code>Collections</code></a> or Google <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Collections2.html" rel="noreferrer"><code>Collections2</code></a> API since a <code>Map</code> is not a <code>Collection</code>. The <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Maps.html#filterEntries%28java.util.Map,%20com.google.common.base.Predicate%29" rel="noreferrer"><code>Maps#filterEntries()</code></a> is also not really useful, since you only know the actual result at <em>end</em> of iteration.</p> <p>Most straightforward solution would then be this:</p> <pre><code>Entry&lt;String, Double&gt; min = null; for (Entry&lt;String, Double&gt; entry : map.entrySet()) { if (min == null || min.getValue() &gt; entry.getValue()) { min = entry; } } System.out.println(min.getKey()); // 0.1 </code></pre> <p>(nullcheck on <code>min</code> left aside)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload