当前位置:网站首页>Map&Set
Map&Set
2022-04-21 20:31:00 【你真是猫改不了吃小鱼干】
Map中存储的就是key-value的键值对,Set中只存储了Key。
Map是一个接口类,该类没有继承自Collection,该类中存储的是结构的键值对,并且K一定是唯一的,不能重复。
关于Map.Entry的说明
Map.Entry 是Map内部实现的用来存放键值对映射关系的内部类,该内部类中主要提供了的获取,value的设置以及Key的比较方式。
| K getKey() |
返回 entry 中的 key |
| V getValue() |
返回 entry 中的 value |
| V setValue(V value) |
将键值对中的value替换为指定value |
Map 的常用方法说明
| V get(Object key) |
返回 key 对应的 value |
| V getOrDefault(Object key, V defaultValue) |
返回 key 对应的 value,key 不存在,返回默认值 |
| V put(K key, V value) |
设置 key 对应的 value |
| V remove(Object key) |
删除 key 对应的映射关系 |
| Set keySet() |
返回所有 key 的不重复集合 |
| Collection values() |
返回所有 value 的可重复集合 |
| Set> entrySet() |
返回所有的 key-value 映射关系 |
| boolean containsKey(Object key) |
判断是否包含 key |
| boolean containsValue(Object value) |
判断是否包含 value |
Set与Map主要的不同有两点:Set是继承自Collection的接口类,Set中只存储了Key。
| boolean add(E e) |
添加元素,但重复元素不会被添加成功 |
| void clear() |
清空集合 |
| boolean contains(Object o) |
判断 o 是否在集合中 |
| Iterator iterator() |
返回迭代器 |
| boolean remove(Object o) |
删除集合中的 o |
| int size() |
返回set中元素的个数 |
| boolean isEmpty() |
检测set是否为空,空返回true,否则返回false |
| Object[] toArray() |
将set中的元素转换为数组返回 |
| boolean containsAll(Collection c) |
集合c中的元素是否在set中全部存在,是返回true,否则返回false |
| boolean addAll(Collection c) |
将集合c中的元素添加到set中,可以达到去重的效果 |
1. Set是继承自Collection的一个接口类
2. Set中只存储了key,并且要求key一定要唯一
3. Set的底层是使用Map来实现的,其使用key与Object的一个默认对象作为键值对插入到Map中的
4. Set最大的功能就是对集合中的元素进行去重
5. 实现Set接口的常用类有TreeSet和HashSet,还有一个LinkedHashSet,LinkedHashSet是在HashSet的基础上维护了一个双向链表来记录元素的插入次序。
6. Set中的Key不能修改,如果要修改,先将原来的删除掉,然后再重新插入
7. Set中不能插入null的key。
版权声明
本文为[你真是猫改不了吃小鱼干]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_60991267/article/details/124280401
边栏推荐
- (转载)MySQL读写分离--集群和高并发
- 【原】biginteger。大数乘法。大数运算。“无限大数字”乘法。大数乘法两种方法对比
- Data preprocessing for data analysis
- Collection of knowledge points
- 实战 | 电商业务性能测试(二): Jmeter 参数化功能实现注册登录的数据驱动
- Android Development Internship interview questions, Android development interview basis
- Click, walk and move of characters in 3D sandbox game
- How to use xUnit framework to maintain test cases?
- 3D 沙盒游戏之人物的点击行走移动
- [CTF. Show. Reverse] Abstract Language
猜你喜欢

Channel allocation don't use the four-color theorem

上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花板

RTMP(3):Protocol Control Message

Man machine verification reCAPTCHA V3 complete instructions

<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(一)

Source insight configuration and problem summary

Changan dark blue c385 product information exposure aims at 200000 level, and the number one target is model 3!

Android Development Internship interview questions, Android development interview basis

Employment of college students in the "most difficult employment season": more than half of the graduates have landed, and higher vocational colleges produce sweet pastries

C语言求完全平方数
随机推荐
Win11高效日历推荐
oracle数据导入记录笔记
华融融达期货这家公司怎么样?期货开户办理安全吗?
php7.2 zend opcache缓存include读取出的内容
My medical experience of "traditional Chinese medicine"
Data preprocessing for data analysis
【转】FC(红白机)游戏nes文件的汉化技术
Practice of spark SQL in snowball
< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (2)
MySQL view (detailed explanation)
他98年的,我玩不过他...
VS2019配置opencv4
The timer class of version C is accurate to microseconds and retains one decimal place after seconds. It supports the output of year, month, day, hour, minute and second with units
php UEditor上传文件(图片视频)到OSS
Vtkjs introduction
单、双链表的循环链表(十五)
Andorid -- why use transactions? What is transaction commit and rollback?
Redis的两种基准性能测试方式
C # cannot be used for characters of file name
[original] popular saying is the story behind the so-called "dynamic pixels" and "static pixels" of digital cameras