Download Set_advanced_project/Set_module/src/HashSet_package/HashSet_demo2.java from zxy0307/Java: direct link, hf CLI and curl.
- Browser
- Download file 967 Bytes
-
https://huggingface.co/zxy0307/Java/resolve/main/Set_advanced_project/Set_module/src/HashSet_package/HashSet_demo2.java
- Command line
-
hf download hf://zxy0307/Java/Set_advanced_project/Set_module/src/HashSet_package/HashSet_demo2.java
-
curl -L -o HashSet_demo2.java https://huggingface.co/zxy0307/Java/resolve/main/Set_advanced_project/Set_module/src/HashSet_package/HashSet_demo2.java
967 Bytes
| package HashSet_package; | |
| import java.util.HashSet; | |
| public class HashSet_demo2 { | |
| public static void main(String[] args) { | |
| /* | |
| 需求:创建一个存储学生对象的集合,存储多个学生对象。 | |
| 使用程序实现在控制台遍历该集合。 | |
| 要求:学生对象的成员变量值相同,我们就认为是同一个对象 | |
| */ | |
| //1、创建三个学生对象 | |
| Student s1 = new Student("zhangsan", 23); | |
| Student s2 = new Student("lisi", 24); | |
| Student s3 = new Student("wangwu", 25); | |
| Student s4 = new Student("zhangsan", 23); | |
| //2、创建集合用来添加学生 | |
| HashSet<Student> hs = new HashSet<>(); | |
| //3、添加元素 | |
| System.out.println(hs.add(s1)); | |
| System.out.println(hs.add(s2)); | |
| System.out.println(hs.add(s3)); | |
| System.out.println(hs.add(s4)); | |
| //4、打印集合 | |
| System.out.println(hs); | |
| } | |
| } | |