Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-training
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
景园园
java-training
Commits
bb0a122d
Commit
bb0a122d
authored
Nov 01, 2018
by
景园园
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HashMap测试类
parent
e0bcec3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
demo1/src/test/java/cn/freemud/demo/HashMapTest.java
+76
-0
No files found.
demo1/src/test/java/cn/freemud/demo/HashMapTest.java
View file @
bb0a122d
package
cn
.
freemud
.
demo
;
package
cn
.
freemud
.
demo
;
import
org.junit.Test
;
import
java.util.HashMap
;
/**
*测试HashMap
* @author jingyuanyuan
*/
public
class
HashMapTest
{
public
class
HashMapTest
{
/**
* HashMap的键和值都可以存储为null
*/
@Test
public
void
test
(){
System
.
out
.
println
(
"hello this is test"
);
HashMap
map
=
new
HashMap
();
map
.
put
(
null
,
"你好"
);
map
.
put
(
"key1"
,
null
);
System
.
out
.
println
(
"map size:"
+
map
.
size
());
System
.
out
.
println
(
"key is null value:"
+
map
.
get
(
null
));
System
.
out
.
println
(
"value is null value:"
+
map
.
get
(
"key1"
));
}
/**
* clear 清空集合
*/
@Test
public
void
clearTest
(){
HashMap
map
=
new
HashMap
();
map
.
put
(
"key1"
,
"张三"
);
System
.
out
.
println
(
"map size:"
+
map
.
size
());
map
.
clear
();
System
.
out
.
println
(
"map size:"
+
map
.
size
());
}
/**
* clone 克隆集合
*/
@Test
public
void
cloneTest
(){
HashMap
map
=
new
HashMap
();
map
.
put
(
"key1"
,
"张三"
);
map
.
put
(
"key2"
,
"李四"
);
System
.
out
.
println
(
"map size:"
+
map
.
size
());
Object
clone
=
map
.
clone
();
System
.
out
.
println
(
"clone map size:"
+
clone
);
}
/**
* 测试集合中是否包含指定的key
*/
@Test
public
void
containsKeyTest
(){
HashMap
map
=
new
HashMap
();
map
.
put
(
"key1"
,
"张三"
);
map
.
put
(
"key2"
,
"李四"
);
boolean
key1
=
map
.
containsKey
(
"key1"
);
boolean
key3
=
map
.
containsKey
(
"key3"
);
System
.
out
.
println
(
"containsKey key1:"
+
key1
);
System
.
out
.
println
(
"containsKey key3:"
+
key3
);
}
/**
* 测试集合中是否包含指定的value
*/
@Test
public
void
containsValueTest
(){
HashMap
map
=
new
HashMap
();
map
.
put
(
"key1"
,
"张三"
);
map
.
put
(
"key2"
,
"李四"
);
boolean
a
=
map
.
containsValue
(
"张"
);
boolean
b
=
map
.
containsValue
(
"李四"
);
System
.
out
.
println
(
"containsValue 张:"
+
a
);
System
.
out
.
println
(
"containsValue 李四:"
+
b
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment