把test.java救回来了

This commit is contained in:
2024-06-11 01:53:01 +08:00
parent d085000064
commit d753356d40
54 changed files with 1309 additions and 1297 deletions
+11 -11
View File
@@ -1,12 +1,12 @@
//HelloCollections.java
package task1;
import java.util.ArrayList;
public class HelloCollections {
public ArrayList run() {
ArrayList<String> list = new ArrayList<>();
list.add("hello, world");
return list;
}
//HelloCollections.java
package task1;
import java.util.ArrayList;
public class HelloCollections {
public ArrayList run() {
ArrayList<String> list = new ArrayList<>();
list.add("hello, world");
return list;
}
}
+12
View File
@@ -0,0 +1,12 @@
//test.java
package task1;
import java.util.ArrayList;
public class test {
public static void main(String[] args) {
HelloCollections h1 = new HelloCollections();
ArrayList a1 = h1.run();
System.out.println(a1);
}
}
+24 -24
View File
@@ -1,25 +1,25 @@
package task2;
import java.util.ArrayList;
import java.util.Iterator;
public class WalkCollection {
public static void main(String[] args) {
ArrayList arrayListExample = new ArrayList();
// ---------------------Begin------------------------
// arrayListExample.add("aaa");
// arrayListExample.add("bbb");
// arrayListExample.add("ccc");
// arrayListExample.add("ddd");
// 展示运行结果前删下注释
// 使用迭代器iterator遍历arrayListExample集合
Iterator itr = arrayListExample.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
// 使用foreach遍历arrayListExample集合
arrayListExample.forEach(System.out::println);
// ---------------------End------------------------
}
package task2;
import java.util.ArrayList;
import java.util.Iterator;
public class WalkCollection {
public static void main(String[] args) {
ArrayList arrayListExample = new ArrayList();
// ---------------------Begin------------------------
// arrayListExample.add("aaa");
// arrayListExample.add("bbb");
// arrayListExample.add("ccc");
// arrayListExample.add("ddd");
// 展示运行结果前删下注释
// 使用迭代器iterator遍历arrayListExample集合
Iterator itr = arrayListExample.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
// 使用foreach遍历arrayListExample集合
arrayListExample.forEach(System.out::println);
// ---------------------End------------------------
}
}
+20 -20
View File
@@ -1,21 +1,21 @@
package task3;
import java.util.HashSet;
import java.util.Scanner;
public class HelloSet {
public static void main(String[] args) {
HashSet<Object> hashSet = new HashSet<>();
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
hashSet.add(scanner.next());
}
// ---------------------Begin------------------------
hashSet.add("helloHashSet");
hashSet.remove("cat");
hashSet.add("fish");
hashSet.remove("apple");
// ---------------------End------------------------
hashSet.forEach(ele -> System.out.println(ele));
}
package task3;
import java.util.HashSet;
import java.util.Scanner;
public class HelloSet {
public static void main(String[] args) {
HashSet<Object> hashSet = new HashSet<>();
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
hashSet.add(scanner.next());
}
// ---------------------Begin------------------------
hashSet.add("helloHashSet");
hashSet.remove("cat");
hashSet.add("fish");
hashSet.remove("apple");
// ---------------------End------------------------
hashSet.forEach(ele -> System.out.println(ele));
}
}
+21 -21
View File
@@ -1,21 +1,21 @@
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------------------------
hashMapExample.put("name", "lihong");
hashMapExample.remove("firstkey");
hashMapExample.replace("secondkey", "educode");
System.out.println(hashMapExample);
// ---------------------End------------------------
}
}
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------------------------
hashMapExample.put("name", "lihong");
hashMapExample.remove("firstkey");
hashMapExample.replace("secondkey", "educode");
System.out.println(hashMapExample);
// ---------------------End------------------------
}
}