0
点赞
收藏
分享

微信扫一扫

Java学习Map之Map集合概述和使用

TiaNa_na 2022-05-10 阅读 93

Map集合概述

Interface Map<K,V> K:键的类型; V:值的类型

将键映射到值的对象;不包含重复的键;每个键可以映射到最多一个值       

举例:学生的学号和姓名

        itheima001  林青霞

        itheima002  张曼玉

        itheima003  王祖贤

创建MAP集合的对象

    多态的方式

    具体的实现类HashMap

package com.itheima_100;

import java.util.HashMap;
import java.util.Map;

/*
Map集合概述
Interface Map<K,V> K:键的类型; V:值的类型
将键映射到值的对象;不包含重复的键;每个键可以映射到最多一个值
举例:学生的学号和姓名
itheima001 林青霞
itheima002 张曼玉
itheima003 王祖贤
创建MAP集合的对象
多态的方式
具体的实现类HashMap
*/
public class MapDemo001 {
public static void main(String[] args) {
//创建Map集合对象
Map<String,String> map = new HashMap<String,String>();

//V put(K key,V value)将指定的值与该映射中的指定键相关联
map.put("itheima001","林青霞");
map.put("itheima002","张曼玉");
map.put("itheima003","王祖贤");
map.put("itheima003","王昱翔");

// //输出集合
System.out.println(map);

}
}

    

举报

相关推荐

0 条评论