<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 如何從`TreeMap`中獲取子映射 - Java > 原文: [https://beginnersbook.com/2014/07/how-to-get-the-sub-map-from-treemap-example-java/](https://beginnersbook.com/2014/07/how-to-get-the-sub-map-from-treemap-example-java/) 在這個例子中,我們將看到如何從`TreeMap`獲取子映射。我們正在使用`TreeMap`類的`subMap()`方法。有關詳細信息,請參閱以下程序中的注釋。 #### 示例 ```java import java.util.*; class TreeMapDemo { public static void main(String args[]) { // Create a TreeMap TreeMap<String, String> treemap = new TreeMap<String, String>(); // Put elements to the map treemap.put("Key1", "Jack"); treemap.put("Key2", "Rick"); treemap.put("Key3", "Kate"); treemap.put("Key4", "Tom"); treemap.put("Key5", "Steve"); treemap.put("Key6", "Ram"); // Displaying TreeMap elements System.out.println("TreeMap Contains : " + treemap); // Getting the sub map /* public SortedMap<K,V> subMap(K fromKey,K toKey): Returns * a view of the portion of this map whose keys range from * fromKey, inclusive, to toKey, exclusive. * (If fromKey and toKey are equal, the returned map is empty.) * The returned map is backed by this map, so changes in the * returned map are reflected in this map, and vice-versa. * The returned map supports all optional map operations that * this map supports. */ SortedMap<String, String> sortedMap = treemap.subMap("Key2","Key5"); System.out.println("SortedMap Contains : " + sortedMap); // Removing an element from Sub Map sortedMap.remove("Key4"); /* Displaying elements of original TreeMap after * removing an element from the Sub Map. Since Sub Map is * backed up by original Map, the element should be removed * from this TreeMap too. */ System.out.println("TreeMap Contains : " + treemap); } } ``` **輸出:** ```java TreeMap Contains : {Key1=Jack, Key2=Rick, Key3=Kate, Key4=Tom, Key5=Steve, Key6=Ram} SortedMap Contains : {Key2=Rick, Key3=Kate, Key4=Tom} TreeMap Contains : {Key1=Jack, Key2=Rick, Key3=Kate, Key5=Steve, Key6=Ram} ``` **參考:** [`subMap()`方法 - `TreeMap` javadoc](https://docs.oracle.com/javase/7/docs/api/java/util/TreeMap.html#subMap(K,%20K)) [SortedMap javadoc](https://docs.oracle.com/javase/7/docs/api/java/util/SortedMap.html)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看