当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢

C code production YUV420 planar format file

4279. Cartesian tree

Common APIs

My 2020 summary "don't love the past, indulge in moving forward"
![[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*](/img/1f/f579110a408c5b5a094733be57ed90.jpg)
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*

C代码生产YUV420 planar格式文件

How to specify the execution order for multiple global exception handling classes

深度学习参数初始化(一)Xavier初始化 含代码
![[set theory] partition (partition | partition example | partition and equivalence relationship)](/img/f0/c3c82de52d563f3b81d731ba74e3a2.jpg)
[set theory] partition (partition | partition example | partition and equivalence relationship)

In depth analysis of reentrantlock fair lock and unfair lock source code implementation
随机推荐
Use the jvisualvm tool ----- tocmat to start JMX monitoring
Advanced API (batch image Download & socket dialog)
Download address collection of various versions of devaexpress
Selenium key knowledge explanation
Advanced API (use of file class)
twenty million two hundred and twenty thousand three hundred and nineteen
mysql误删root账户导致无法登录
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Summary of abnormal mechanism of interview
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
Advanced APL (realize group chat room)
Arduino Serial系列函数 有关print read 的总结
Jeecg menu path display problem
Pits encountered in the use of El checkbox group
gstreamer ffmpeg avdec解码数据流向分析
RestHighLevelClient获取某个索引的mapping
Advanced API (local simulation download file)
Jeecg data button permission settings
Crontab scheduled task
Le Seigneur des anneaux: l'anneau du pouvoir