From 2c7ad64d2f82269f59ccc8d0e33cbe21b32f75ef Mon Sep 17 00:00:00 2001 From: msksbr Date: Mon, 10 Jun 2024 18:38:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E5=AE=9E=E9=AA=8C=E4=B8=83=E5=AE=9E?= =?UTF-8?q?=E9=AA=8C=E6=8A=A5=E5=91=8A=E9=87=8C=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8B=B7=E8=BF=9B=E6=9D=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 实验7/src/task1/HelloCollections.java | 9 +++++++++ 实验7/src/task2/WalkCollection.java | 14 ++++++++++++++ 实验7/src/task3/HelloSet.java | 17 +++++++++++++++++ 实验7/src/task4/HelloHashMap.java | 17 +++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 实验7/src/task1/HelloCollections.java create mode 100644 实验7/src/task2/WalkCollection.java create mode 100644 实验7/src/task3/HelloSet.java create mode 100644 实验7/src/task4/HelloHashMap.java diff --git a/.gitignore b/.gitignore index 0d839b7..056e6fb 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ hs_err_pid* #实验报告 *.docx *.doc +*.docx# #test.java test.java \ No newline at end of file diff --git a/实验7/src/task1/HelloCollections.java b/实验7/src/task1/HelloCollections.java new file mode 100644 index 0000000..d4ac3ca --- /dev/null +++ b/实验7/src/task1/HelloCollections.java @@ -0,0 +1,9 @@ +package task1; + +import java.util.ArrayList; + +public class HelloCollections { + public ArrayList run() { + return list; + } +} \ No newline at end of file diff --git a/实验7/src/task2/WalkCollection.java b/实验7/src/task2/WalkCollection.java new file mode 100644 index 0000000..8f20b3b --- /dev/null +++ b/实验7/src/task2/WalkCollection.java @@ -0,0 +1,14 @@ +package task2; + +import java.util.ArrayList; +import java.util.Iterator; + +public class WalkCollection { + public static void main(String[] args) { + ArrayList arrayListExample = new ArrayList(); + // ---------------------Begin------------------------ + // 使用迭代器iterator遍历arrayListExample集合 + // 使用foreach遍历arrayListExample集合 + // ---------------------End------------------------ + } +} \ No newline at end of file diff --git a/实验7/src/task3/HelloSet.java b/实验7/src/task3/HelloSet.java new file mode 100644 index 0000000..3317af3 --- /dev/null +++ b/实验7/src/task3/HelloSet.java @@ -0,0 +1,17 @@ +package task3; + +import java.util.HashSet; +import java.util.Scanner; + +public class HelloSet { + public static void main(String[] args) { + HashSet hashSet = new HashSet<>(); + Scanner scanner = new Scanner(System.in); + for (int i = 0; i < 5; i++) { + hashSet.add(scanner.next()); + } + // ---------------------Begin------------------------ + // ---------------------End------------------------ + hashSet.forEach(ele -> System.out.println(ele)); + } +} \ No newline at end of file diff --git a/实验7/src/task4/HelloHashMap.java b/实验7/src/task4/HelloHashMap.java new file mode 100644 index 0000000..28061b0 --- /dev/null +++ b/实验7/src/task4/HelloHashMap.java @@ -0,0 +1,17 @@ +package task4; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Scanner; + +public class HelloHashMap { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + HashMap hashMapExample = new HashMap<>(); + for (int i = 0; i < 2; i++) { + hashMapExample.put(scanner.next(), scanner.next()); + } + // ---------------------Begin------------------------ + // ---------------------End------------------------ + } +}