当前位置:网站首页>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]
边栏推荐
- 关于 CMS 垃圾回收器,你真的懂了吗?
- 20210520 TCP sliding window
- JVM memory layout detailed, illustrated, well written!
- Security measures for tcp/ip protocol vulnerabilities
- Redis data type
- Plus版SBOM:流水线物料清单PBOM
- Go Introduction (2)
- Redis distributed online installation
- Will MySQL fail to insert data? Why?
- CMD Chinese garbled code solution
猜你喜欢

Chapter 12 generics
![[database data recovery] a data recovery case in which the disk partition where the SQL Server database is located is insufficient and an error is reported](/img/8a/478209854cb5ce139afc338d106d36.png)
[database data recovery] a data recovery case in which the disk partition where the SQL Server database is located is insufficient and an error is reported

Complete data summary of lapsus$apt organization that stole Microsoft's source code in March 2022

多表查询

Chapter 7 exception handling

About the problem that the onapplicationevent method of the custom listener is executed multiple times

SparkSubmit.main()方法提交外部参数,远程提交standalone集群任务

HDU1698_ Just a Hook

Detail throw and throws

Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning
随机推荐
Self built personalized automatic quotation system to cope with changeable quotation mode
Application parameters of Southern biotech HRP labeled avidin avidin avidin
Soft core microprocessor
Go Introduction (2)
A personal blog integrating technology, art and sports.
Log4j2.xml configuration details
Photoshop web design tutorial
关于2022年3月9日之后Typora登录不了--已解决
20210519 leetcode double pointer
POJ1611_ The Suspects
Nodejs body parser middleware processes post form data of type multipart / form data, and req.body cannot receive data
开关量输入输出模块DAM-5055
Vi. analysis of makefile.build
POJ1611_The Suspects
20210422 consolidation interval
Plus SBOM: assembly line BOM pbom
概述有名内部类与匿名内部类
When the script runs in the background, it redirects the log from the console to its own named file
5V boost 9V chip
I/o instance operation