首页 > 其他分享 >Map集合

Map集合

时间:2023-03-21 20:11:20浏览次数:32  
标签:Map map System put key 集合 println out

  • 概念:一种可以自行定义检索规则的数据结构,也叫字典
  • 构成:key - value

注意:

  1. null值可以作为key
  2. key值具有唯一性
  3. HasMmap的Key其本质是数组+链表构成的红黑树
点击查看代码
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Main1 {
public static void main(String[] args) {
Map<String,Object> map = new HashMap<>();
//存值
map.put("k1",100);
map.put("k2",200);
map.put("k3",300);
map.put("k3",400);//覆盖前一个值
//取值
System.out.println(map.get("k1"));
System.out.println(map.get("k2"));
System.out.println(map.get("k3"));
//判断某个key是否存在
System.out.println(map.containsKey("k1"));
//判断某个value是否存在
System.out.println(map.containsValue(100));
//一个特殊的key
map.put(null,500);
map.put(null,600);
map.put(null,700);
System.out.println(map.get(null));
//分别获取key和value的集合
Set<String> keys = map.keySet();//不可重复
Collection<?> values = map.values();//可以重复
}
}

标签:Map,map,System,put,key,集合,println,out
From: https://www.cnblogs.com/qiyuancc/p/17241264.html

相关文章

  • List集合
    特点有序,有重复实现类1.ArrayList是一个基于数组的集合,其扩容策略为,默认为0,添加第一个元素直接扩展到10,此后每次扩容50%。常用API点击查看代码importjava.util.Ar......
  • HashMap底层源码分析
    HashMap底层源码分析今天先简单看看HashMap的底层源码,之后做详细的分析以及与其他集合的对比。1.看源码之前需要了解的一些内容Node<K,V>[]table哈希表结构中数组......
  • Stream流中的flatMap
    @TestvoidcontextLoads(){//字符串判NULLList<Optional<String>>list=Arrays.asList(Optional.of("A"),Optio......
  • 在map 枚举过程中删去整个map的错误
    Programterminatedwithsignal11,Segmentationfault.#0 0x00007fad0af884c7instd::_Rb_tree_increment(std::_Rb_tree_node_base*)()from/lib64/libstdc++.so.......
  • 集合框架
    集合框架1.List接口2.Set接口3,Map接口一、集合的体系1.Collection接口也是一种集合,特征:无序,可重复无序:没有游标可重复:这个集合当中可以有相同的数据注意:没有......
  • 力扣 49 字母异位词分组 multimap
    classSolution{public:vector<vector<string>>groupAnagrams(vector<string>&strs){multimap<string,string>mp;//键排序,值没动intlen=s......
  • Hashtable 键值对集合
    usingSystem;usingSystem.Collections;namespaceHashtable_键值对集合{classProgram{staticvoidMain(string[]args){......
  • ArrayList集合对象
    1、ArrayList集合对象usingSystem;usingSystem.Collections;namespaceArrayList集合{classProgram{staticvoidMain(string[]args)......
  • List 泛型集合
     usingSystem;usingSystem.Collections.Generic;namespaceList_泛型集合{classProgram{staticvoidMain(string[]args){......
  • java实现多字段排序(普通对象List和MapList)
    publicclassSortTest{publicstaticvoidmain(String[]args){//普通对象listsortVOList();//mapListsortMapList();......