public class TestMap {
public static void main(String[] args) {
Student s1 = new Student("蔡徐坤",20,"大四","北京大学");
Student s2 = new Student("罗志祥",30,"大三","家里蹲");
Student s3 = new Student("人才",40,"大一","外国语");
Map<String,Student> studentMap = new HashMap<>();
studentMap.put(s1.name,s1);
studentMap.put(s2.name,s2);
studentMap.put(s3.name,s3);
String name = "蔡徐坤";
String name1 = "厉害";
Student student = studentMap.get(name);
Student student1 = studentMap.getOrDefault(name1,new Student("moren ",10,"moren","moren"));
System.out.println(student);
System.out.println(student1);
for (Map.Entry<String,Student> entry:studentMap.entrySet()) {
System.out.println(entry.getKey()+":"+entry.getValue());
}
}
}
public class TestSet {
public static void main(String[] args) {
Set<String> set = new HashSet<>();
set.add("JAVA");
set.add("JAVA");
set.add("JAVA");
set.add("C++");
set.add("Python");
set.add("JS");
System.out.println(set.contains("JAVA"));
set.remove("C++");
System.out.println(set.contains("C++"));
System.out.println(set);
for (String s:set) {
System.out.println(s);
}
Iterator<String> iterator = set.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}