当前位置:网站首页>Map interface
Map interface
2022-07-27 12:39:00 【Rippling rippling】
Relationship

Common methods
1.put(K key, V value)
effect :
Will key (key)/ value (value) Map to Map Collection , Simply put, it is equivalent to the two values you enter key and values Each is a circle , Then they are surrounded by a big circle , When you call , If no other method to separate them is called , Generally, they call the big circle formed by them directly .
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
System.out.println(hashmap.get("key"));
}
}
result :
35663
2.get(Object key)
effect :
Returns the specified key key Mapped values , There is no the key The corresponding value returns null.
notes : Can only be key .
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.get("key"));
}
}
result :
35663
3.size()
effect :
return Map The amount of data in the collection
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.size());
}
}
result :
3
4.clear()
effect :
Empty Map aggregate
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.size());
hashmap.clear();
System.out.println(hashmap.size());
}
}
result :
3
0
5.isEmpty ()
effect :
Judge Map Whether there is data in the collection , If not, return true, Otherwise return to false
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.isEmpty());
hashmap.clear();
System.out.println(hashmap.isEmpty());
}
}
result :
false
true
6.remove(Object key)
effect :
Delete Map Collect the data of the key in the and return its corresponding value value .
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.remove("key"));
System.out.println(hashmap.size());
}
}
result :
35663
2
7.values()
effect :
return Map All in the assembly value Consisting of Collection Data type format data .
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.remove("key"));
System.out.println(hashmap.values());
System.out.println(hashmap.size());
}
}
result :
35663
[3465, 32757]
2
8.contains Key(Object key)
effect :
Determine whether the specified key is included in the set , Include return true, Otherwise return to false
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.remove("key"));
System.out.println(hashmap.values());
System.out.println(hashmap.size());
System.out.println(hashmap.containsKey("dfshl"));
}
}
result :
35663
[3465, 32757]
2
false
9.containsValue(Object value)
effect :
Determine whether the set contains the specified value , Include return true, Otherwise return to false
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.remove("key"));
System.out.println(hashmap.values());
System.out.println(hashmap.size());
System.out.println(hashmap.containsKey("dfshl"));
System.out.println(hashmap.containsValue(3465));
}
}
result :
35663
[3465, 32757]
2
false
true
10.keySet()
effect :
return Map All in the assembly key Composed of Set aggregate
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.remove("key"));
System.out.println(hashmap.values());
System.out.println(hashmap.size());
System.out.println(hashmap.containsKey("dfshl"));
System.out.println(hashmap.containsValue(3465));
System.out.println(hashmap.keySet());
}
}
result :
35663
[3465, 32757]
2
false
true
[ht, srht]
11.entrySet()
effect :
take Map Assemble each key-value Convert to a Entry Object and return by all Entry Made up of objects Set aggregate
example :
package Hashmap;
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String,Integer> hashmap=new HashMap<>();
hashmap.put("key", 35663);
hashmap.put("srht", 32757);
hashmap.put("ht", 3465);
System.out.println(hashmap.entrySet());
}
}
result :
[ht=3465, key=35663, srht=32757]
边栏推荐
- BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)
- 评价自动化测试优劣的隐性指标
- CMD Chinese garbled code solution
- 概述静态内部类与非静态内部类
- BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (
- Keil mdk5.37 and above can add AC5 (armcc) compiler by themselves
- Plus SBOM: assembly line BOM pbom
- P1876 turn on the light [getting started]
- Go Beginner (4)
- Julia beginner tutorial 2022
猜你喜欢

Configuration files in MySQL

II. Analysis of the execution process of make menuconfig

J9 number theory: how long is the mainstreaming of decentralized identity?

The strongest distributed locking tool: redisson

Photoshop web design tutorial

Error: the source of the existing CacheManager is: urlconfigurationsource

Chapter 8 multithreading

隔离级别

BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)

Why does MySQL index use b+ tree instead of jump table?
随机推荐
Error: the source of the existing CacheManager is: urlconfigurationsource
【表达式计算】双栈 : 表达式计算问题的通用解法
js真伪数组转换
Keil mdk5.37 and above can add AC5 (armcc) compiler by themselves
分布式系统架构理论与组件
SQL question brushing: find out the current salary of all employees
Go Beginner (5)
Detailed explanation of flask framework
Recursive method | Fibonacci sequence
How to design a secure external interface
Chapter 12 generics
SparkSubmit.main()方法提交外部参数,远程提交standalone集群任务
5V boost 9V chip
Why does MySQL index use b+ tree instead of jump table?
关于 CMS 垃圾回收器,你真的懂了吗?
US pressure surges tiktok changes global safety director
Set接口
The strongest distributed locking tool: redisson
HDU1698_ Just a Hook
An overview of kernel compilation system