Java-Map集合的學習

來源:互聯網
上載者:User

標籤:image   iterator   ref   來講   info   pack   執行個體化   strong   技術分享   

 

1. Map1.1. map中的方法

1.2. Map.Entry

對於集合來講,就是把kye-value的資料儲存在了Map.Entry的執行個體之後,再在Map集合中插入了一個Map.Entry的執行個體化對象

Map.Entry一般用於輸出集合

1.3. Map介面的常用子類

1.4. HashTable和HashMap區別

1.5. Map的標準輸出(2個)

方案一:

 

方案二:

package com.ftl;import java.util.Collection;import java.util.Iterator;import java.util.Map;import java.util.Map.Entry;import java.util.Set;import java.util.TreeMap;public class Test2018 {    public static void main(String[] args) {        Map<String, String> map = new TreeMap<>();        map.put("Hello", "world");        map.put("Hello1", "world1");        map.put("Hello2", "world2");        map.put("Hello3", "world3");        String str = map.get("Hello");        Set<String> set = map.keySet();        Collection<String> values = map.values();        Iterator<String> iterator = set.iterator();        Iterator<String> iter = values.iterator();        System.out.println("\nforeach方法:");        for (String s : values) {            System.out.print(s + "、");        }        System.out.println("\nIterator方法:");        while (iterator.hasNext()) {            System.out.print(iterator.next() + "、");        }        System.out.println("\nMap的標準輸出_1(Map.entrySet):");        Set<Entry<String, String>> entrySet = map.entrySet();        Iterator<Map.Entry<String, String>> it = entrySet.iterator();        while (it.hasNext()) {            Map.Entry<String, String> next = it.next();            System.out.print(next.getKey() + "-->: " + next.getValue() + "\n");        }        System.out.println("\nMap的標準輸出_2(Foreach):");        for (Map.Entry<String, String> entry : entrySet) {            System.out.print(entry.getKey() + "-->: " + entry.getValue() + "\n");        }        System.out.println("Map.entrySet()大小:" + map.entrySet().size());    }}
1.6. 人員配置

Java-Map集合的學習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.