直接上代码

package com.ys.msjihe18;

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

/*
 * 		Map常见的几个功能方法的测试
 */
public class MapDemo02 {
	public static void main(String[] args) {
		Map<Integer,String> map = new HashMap<Integer,String>();
		
		// V put(K key, V value)  映射功能,可以输入也可以顶替
		System.out.println(map.put(001, "杨帅"));
		System.out.println(map.put(002, "龚仕蓉"));
		System.out.println(map.put(001, "杨狗蛋"));
		
		// boolean containsKey(Object key)  判断键是否存在
		System.out.println(map.containsKey(004));
		
	    // boolean containsValue(Object value) 判断值是否存在
		System.out.println(map.containsValue("杨狗蛋"));
		
		// boolean isEmpty()  判断是否为空
		System.out.println(map.isEmpty());
		
		
		// V remove(Object key)  删除方法,输入键,删除键和值,返回值
		System.out.println(map.remove(001));
		 
		//get方法  返回value
		String s = map.get(002);
		System.out.println(s);
		
		map.clear();//清除的方法
		
		System.out.println(map);
	}
}



运行结果
Map的功能概述和测试

相关文章:

  • 2021-09-30
  • 2021-06-07
  • 2021-07-19
  • 2022-12-23
  • 2022-02-03
  • 2022-01-19
  • 2022-01-05
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2021-06-28
  • 2021-12-14
  • 2021-09-29
  • 2021-12-03
  • 2021-08-24
  • 2021-05-06
相关资源
相似解决方案