Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TreeMap.html" rel="noreferrer"><code>TreeMap</code></a>, which is an implementation of the <code>SortedMap</code> interface. It presents its keys in sorted order.</p> <pre><code>Map&lt;String, Object&gt; map = new TreeMap&lt;String, Object&gt;(); /* Add entries to the map in any order. */ ... /* Now, iterate over the map's contents, sorted by key. */ for (Map.Entry&lt;String, ?&gt; entry : map.entrySet()) { System.out.println(entry.getKey() + ": " + entry.getValue()); } </code></pre> <p>If you are working with another Map implementation that isn't sorted as you like, you can pass it to the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TreeMap.html#TreeMap(java.util.Map)" rel="noreferrer">constructor</a> of <code>TreeMap</code> to create a new map with sorted keys.</p> <pre><code>void process(Map&lt;String, Object&gt; original) { Map&lt;String, Object&gt; copy = new TreeMap&lt;String, Object&gt;(original); /* Now use "copy", which will have keys in sorted order. */ ... } </code></pre> <p>A <code>TreeMap</code> works with any type of key that implements the <code>Comparable</code> interface, putting them in their "natural" order. For keys that aren't <code>Comparable</code>, or whose natural ordering isn't what you need, you can implement your own <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Comparator.html" rel="noreferrer"><code>Comparator</code></a> and specify that in the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TreeMap.html#TreeMap(java.util.Comparator)" rel="noreferrer">constructor</a>.</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