<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # `HashMap` - 從鍵中獲取值 > 原文: [https://beginnersbook.com/2014/08/hashmap-get-value-from-key-example/](https://beginnersbook.com/2014/08/hashmap-get-value-from-key-example/) #### 描述 在提供鍵時從`HashMap`獲取值的程序。 #### 示例 ```java import java.util.HashMap; class HashMapDemo{ public static void main(String[] args) { // Create a HashMap HashMap<Integer, String> hmap = new HashMap<Integer, String>(); //add elements to HashMap hmap.put(1, "AA"); hmap.put(2, "BB"); hmap.put(3, "CC"); hmap.put(4, "DD"); // Getting values from HashMap String val=hmap.get(4); System.out.println("The Value mapped to Key 4 is:"+ val); /* Here Key "5" is not mapped to any value so this * operation returns null. */ String val2=hmap.get(5); System.out.println("The Value mapped to Key 5 is:"+ val2); } } ``` **輸出:** ```java The Value mapped to Key 4 is:DD The Value mapped to Key 5 is:null ``` 注意:在上面的程序中,鍵 5 沒有映射到任何值,因此`get()`方法返回`null`,但是您不能使用此方法來檢查`HashMap`中是否存在某個鍵,因為返回值`null`不一定表示映射不包含鍵;映射也可能將鍵明確映射為`null`。您必須使用`containsKey()`方法來檢查`HashMap`中鍵[是否存在](https://beginnersbook.com/2014/07/java-check-if-a-particular-key-exists-in-hashmap-example/)。
                  <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>

                              哎呀哎呀视频在线观看