<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國際加速解決方案。 廣告
                # Java - 從`HashMap`中刪除所有映射 > 原文: [https://beginnersbook.com/2014/07/java-remove-all-mappings-from-hashmap-example/](https://beginnersbook.com/2014/07/java-remove-all-mappings-from-hashmap-example/) #### 示例 在上一篇教程中,我們分享了如何[根據鍵](https://beginnersbook.com/2014/07/java-remove-mapping-from-hashmap-example/)從`HashMap`中刪除特定的映射。在這個例子中,我們將看到如何從`HashMap`中刪除所有映射。我們將使用[`HashMap`類](https://beginnersbook.com/2013/12/hashmap-in-java-with-example/)的 [`clear()`方法](https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html#clear())來做到這一點: `public void clear()`:從此映射中刪除所有映射。此調用返回后,映射將為空。 **完整代碼:** ```java import java.util.HashMap; public class RemoveAllExample { public static void main(String[] args) { // Creating a HashMap of int keys and String values HashMap<Integer, String> hashmap = new HashMap<Integer, String>(); // Adding Key and Value pairs to HashMap hashmap.put(11,"Value1"); hashmap.put(22,"Value2"); hashmap.put(33,"Value3"); hashmap.put(44,"Value4"); hashmap.put(55,"Value5"); // Displaying HashMap Elements System.out.println("HashMap Elements: " + hashmap); // Removing all Mapping hashmap.clear(); // Displaying HashMap Elements after remove System.out.println("After calling clear():"); System.out.println("---------------------"); System.out.println("HashMap Elements: " + hashmap); } } ``` **輸出:** ```java HashMap Elements: {33=Value3, 55=Value5, 22=Value2, 11=Value1, 44=Value4} After calling clear(): --------------------- HashMap Elements: {} ``` 正如您所看到的,在調用`clear()`方法之后,`HashMap`的所有映射都已被刪除,之后`HashMap`變為空。
                  <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>

                              哎呀哎呀视频在线观看