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
20ad6994
Commit
20ad6994
authored
Nov 01, 2018
by
景园园
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set测试类
parent
fee142f4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
demo1/src/test/java/cn/freemud/demo/SetTest.java
+60
-0
No files found.
demo1/src/test/java/cn/freemud/demo/SetTest.java
View file @
20ad6994
...
...
@@ -38,4 +38,64 @@ public class SetTest {
empty
=
set
.
isEmpty
();
System
.
out
.
println
(
"empty:"
+
empty
);
}
/**
* 测试Set集合的contains方法
* 判断集合里面是否有指定的对象
*/
@Test
public
void
containsTest
()
{
Set
set
=
new
HashSet
();
boolean
flag
=
set
.
contains
(
"zhangsan"
);
System
.
out
.
println
(
"flag:"
+
flag
);
set
.
add
(
"zhangsan"
);
set
.
add
(
"lisi"
);
flag
=
set
.
contains
(
"zhangsan"
);
System
.
out
.
println
(
"flag:"
+
flag
);
}
/**
* 测试Set集合的toArray方法
* 将集合转换为数据
*/
@Test
public
void
toArrayTest
()
{
Set
set
=
new
HashSet
();
set
.
add
(
"zhangsan"
);
set
.
add
(
"lisi"
);
Object
[]
objects
=
set
.
toArray
();
for
(
Object
o
:
objects
)
{
System
.
out
.
println
(
"o:"
+
o
);
}
}
/**
* 测试Set集合的remove方法
* 移除指定的对象
*/
@Test
public
void
removeTest
()
{
Set
set
=
new
HashSet
();
set
.
add
(
"zhangsan"
);
set
.
add
(
"lisi"
);
set
.
remove
(
"lisi"
);
System
.
out
.
println
(
"set:"
+
set
);
}
/**
* 测试Set集合的clear方法
* 清空集合
*/
@Test
public
void
clearTest
()
{
Set
set
=
new
HashSet
();
set
.
add
(
"zhangsan"
);
set
.
add
(
"lisi"
);
System
.
out
.
println
(
"isEmpty:"
+
set
.
isEmpty
());
set
.
clear
();
System
.
out
.
println
(
"isEmpty:"
+
set
.
isEmpty
());
}
}
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