当前位置:网站首页>Map interface and method
Map interface and method
2022-07-03 07:21:00 【four thousand three hundred and forty-three】



value Time repeatable , But disorderly , use Collection For short .
Entry: Key value pair object .
stay Map Class design is , Provides a nested interface (static Modified interface ):Entry.Entry Encapsulate the correspondence of key value pairs into objects , Key value pair object , So we're walking through Map When the collection , From each key value pair (Entry) Object to get the corresponding key and the corresponding value .
HashMap Implementation principle of JDK7 in

stay JDK8 in :
Map Interface method :

package MapInterface;
import org.junit.Test;
import java.util.*;
/*
map Common methods in interfaces
*/
public class MapMethod {
@Test
public void test1(){
Map map = new HashMap();
map.put("aa",123);
map.put("bb",456);
map.put("cc",789);
map.put("dd",101112);
System.out.println(map);
Map map1 = new HashMap();
// modify
map1.put("cc",123);
map1.put("dd",123);
map.putAll(map1);
System.out.println(map);
// remove(Object key)
Object value = map.remove("cc");
System.out.println(value);
System.out.println(map);
// clear() Empty map Data in , And map=null Different
map.clear();
System.out.println(map);
}
// Element query
@Test
public void test2(){
Map map = new HashMap();
map.put("aa",123);
map.put(123,"aa");
map.put("bb",456);
// get(key)
System.out.println(map.get(123));
// containisKey(key)
boolean isExist = map.containsKey("bb");
System.out.println(isExist);
// containisValue(value)
isExist = map.containsValue(123);
System.out.println(isExist);
Map map1 = new HashMap();
map1.put(123,"aa");
map1.put("aa",123);
map1.put("bb",456);
System.out.println(map.equals(map1));
}
@Test
public void test3(){
Map map = new HashMap();
map.put(123,1);
map.put(012,2);
map.put(456,4);
System.out.println(map);
}
@Test
// keySet: Traverse key、value、key-value aggregate .
public void test4(){
Map map = new HashMap();
map.put(123,1);
map.put(012,2);
map.put(456,4);
// Traverse key
Set set = map.keySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()){
System.out.println(iterator.next());
}
// Traverse value
Collection values = map.values();
for (Object obj : values){
System.out.println(obj);
}
// The way 1:
Set keyValue = map.entrySet();
Iterator iterator1 = keyValue.iterator();
while (iterator1.hasNext()) {
// Object key = iterator1.next();
// Map.Entry entry = (Map.Entry)key;
// System.out.println(entry.getKey()+"===="+entry.getValue());
System.out.println(iterator1.next());
}
// The way 2:
Set keySet = map.keySet();
Iterator iterator2 = keySet.iterator();;
while(iterator2.hasNext()){
Object key = iterator2.next();
Object value = map.get(key);
System.out.println(key+"===="+value);
}
}
}
边栏推荐
- Advanced API (batch image Download & socket dialog)
- Jeecg data button permission settings
- Arduino 软串口通信 的几点体会
- centos php7.2.24升级到php7.3
- Win 2008 R2 crashed at the final installation stage
- [solved] win10 cannot find a solution to the local group policy editor
- 带你全流程,全方位的了解属于测试的软件事故
- LeetCode
- 2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- 7.2刷题两个
猜你喜欢

Common APIs

Interview questions about producers and consumers (important)

C code production YUV420 planar format file

Inno Setup 制作安装包

docker建立mysql:5.7版本指定路径挂载不上。
![Gridome + strapi + vercel + PM2 deployment case of [static site (3)]](/img/65/8d79998e96a2c74ba6e237bee652c6.jpg)
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]

691. Cube IV

多个全局异常处理类,怎么规定执行顺序

【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘

高并发内存池
随机推荐
php安装swoole扩展
Jeecg data button permission settings
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
SecureCRT取消Session记录的密码
Advanced API (character stream & net for beginners)
File links cannot be opened or downloaded in Google browser
Store WordPress media content on 4everland to complete decentralized storage
Dora (discover offer request recognition) process of obtaining IP address
Basic knowledge about SQL database
Distributed transactions
深度学习参数初始化(一)Xavier初始化 含代码
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
gstreamer ffmpeg avdec解码数据流向分析
Margin left: -100% understanding in the Grail layout
4279. Cartesian tree
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
Final, override, polymorphism, abstraction, interface
My 2020 summary "don't love the past, indulge in moving forward"
Common APIs