Android(java)學習筆記103:Map集合的擷取功能

來源:互聯網
上載者:User

標籤:

 1 package cn.itcast_01; 2  3 import java.util.Collection; 4 import java.util.HashMap; 5 import java.util.Map; 6 import java.util.Set; 7  8 /* 9  * 擷取功能:10  * V get(Object key):根據鍵擷取值11  * Set<K> keySet():擷取集合中所有鍵的集合12  * Collection<V> values():擷取集合中所有值的集合13  */14 public class MapDemo2 {15     public static void main(String[] args) {16         // 建立集合對象17         Map<String, String> map = new HashMap<String, String>();18 19         // 建立元素並添加元素20         map.put("鄧超", "孫儷");21         map.put("黃曉明", "楊穎");22         map.put("周杰倫", "蔡依林");23         map.put("劉愷威", "楊冪");24 25         // V get(Object key):根據鍵擷取值26         System.out.println("get:" + map.get("周杰倫"));27         System.out.println("get:" + map.get("周傑")); // 返回null28         System.out.println("----------------------");29 30         // Set<K> keySet():擷取集合中所有鍵的集合31         Set<String> set = map.keySet();32         for (String key : set) {33             System.out.println(key);34         }35         System.out.println("----------------------");36 37         // Collection<V> values():擷取集合中所有值的集合38         Collection<String> con = map.values();39         for (String value : con) {40             System.out.println(value);41         }42     }43 }

 

Android(java)學習筆記103: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.