package kgc_byme.day17.homework5.tee;
import java.util.*;
/**
* @Description:
* @author:myh
* @date: 2021/6/2 17:23
*/
public class test {
public static void main(String[] args) {
String cid;
Stu stu[]=new Stu[10];
Map<String, Stu>c1=new HashMap<>();
Map<String, Stu>c2=new HashMap<>();
stu[0]=new Stu("1","dsda",77);
stu[1]=new Stu("2","ds",66);
stu[2]=new Stu("3","sa",87);
stu[3]=new Stu("4","cxz",32);
stu[4]=new Stu("5","dwd",76);
stu[5]=new Stu("1","myh",66);
stu[6]=new Stu("2","ef",56);
stu[7]=new Stu("3","aA",66);
stu[8]=new Stu("4","KJ",99);
stu[9]=new Stu("5","AS",77);
Map<String,Map<String, Stu>> map=new HashMap<>();
for (int i = 0; i < stu.length; i++) {
if(i<5){
c1.put((i+1)+"", stu[i]);
}else{
c2.put((i+1-5)+"", stu[i]);
}
}
Stu stux;
map.put("c1",c1);
map.put("c2",c2);
Set<Map.Entry<String, Map<String, Stu>>> entrySetmap = map.entrySet();
for (Map.Entry<String, Map<String, Stu>> entry : entrySetmap) {
Map<String, Stu> everyclassStu = entry.getValue();
System.out.println("班级:"+entry.getKey());
Set<String> everystuNo = everyclassStu.keySet();
Iterator<String> iterator = everystuNo.iterator();
while ((iterator.hasNext())){
String stuNO=iterator.next();
System.out.print(stuNO+" ");
stux=everyclassStu.get(stuNO);
System.out.println(stux);
}
}
System.out.println("-------手动录入");
Map<String,Map<String, Stu>> map2=new HashMap<>();
Scanner sc=new Scanner(System.in);
System.out.println("请输入");
int classNums= sc.nextInt();
for (int i = 1; i <= classNums; i++) {
System.out.println("输入班级编号");
String classNo=sc.next();
System.out.println("每个班级多少人");
int classStus=sc.nextInt();
Map<String, Stu> everyClassMap = new HashMap<>();
for (int i1 = 1; i1 <=classStus; i1++) {
System.out.println("录入学号");
String stuNo=sc.next();
everyClassMap.put(stuNo,new Stu(stuNo,"zs"+i,18+i));
}
map2.put(classNo,everyClassMap);
}
//遍历m2
map2.forEach((key,value)->{
System.out.println("班级编号"+key);
value.forEach((k,v)->{
System.out.println("学号"+k);
System.out.println("对应信息"+v);
});
});
}
}
class Stu{
String id;
String name;
int score;
public Stu(String id, String name, int score) {
this.id = id;
this.name = name;
this.score = score;
}
@Override
public String toString() {
return "Stu{" +
"id=" + id +
", name='" + name + '\'' +
", score=" + score +
'}';
}
}
hashmap使用的练习
最新推荐文章于 2023-03-28 14:50:19 发布