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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 自定義對象存儲和遍歷 HashMap允許存儲null鍵,null值 , 但是只能存儲一對 . ### 字符串作為key #### for循環 ~~~ HashMap<String, Person> map = new HashMap<String, Person>(); map.put("杭州", new Person("jack", 20)); map.put("北京", new Person("richard", 19)); map.put("無錫", new Person("milan", 18)); for (String key : map.keySet()) { Person value = map.get(key); System.out.println(key+":"+value); } ~~~ 結果 ~~~ 杭州:jack--20 無錫:milan--18 北京:richard--19 ~~~ #### entry ~~~ HashMap<String, Person> map = new HashMap<String, Person>(); map.put("杭州", new Person("jack", 20)); map.put("北京", new Person("richard", 19)); map.put("無錫", new Person("milan", 18)); Set<Map.Entry<String,Person>> set = map.entrySet(); Iterator<Map.Entry<String,Person>> it = set.iterator(); while(it.hasNext()){ Map.Entry<String,Person> entry = it.next(); System.out.println(entry.getKey()); System.out.println(entry.getValue()); } ~~~ ### 自定義對象為key **必須重寫hashCode()和equals()方法** 才能保證對象的唯一性 . person類 ~~~ public class Person { public String name; public int age; public Person(String name, int age) { this.name = name; this.age = age; } public String toString() { return this.name + "--" + this.age; } public int hashCode() { return this.name.hashCode() + this.age * 2; //重寫hashCode } public boolean equals(Object object) //重寫equals { if (object == this) return true; if (!(object instanceof Person)) { return false; } Person person = (Person) object; return person.name.equals(this.name) && person.age == this.age; } } ~~~ ~~~ HashMap<Person, String> map = new HashMap<Person, String>(); map.put(new Person("jack", 18), "北京"); map.put(new Person("jack", 19), "無錫"); map.put(new Person("jack", 19), "杭州"); Set<Map.Entry<Person,String>> p = map.entrySet(); Iterator<Map.Entry<Person,String>> it = p.iterator(); while(it.hasNext()){ Map.Entry<Person,String> entry = it.next(); System.out.println(entry.getKey()); System.out.println(entry.getValue()); } ~~~ ~~~ jack--18 北京 jack--19 杭州 ~~~
                  <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>

                              哎呀哎呀视频在线观看