为了账号安全,请及时绑定邮箱和手机立即绑定

为什么输出的是key值?哪位大佬告诉我哈

public class MapTest {

public Map<String, Student> students;


public MapTest() {

this.students = new HashMap();

}


public void mapAdd() {

Scanner console = new Scanner(System.in);


int i = 0;

while (i < 3) {

System.out.println("请输入学生ID:");

String ID = console.next();

Student stu = students.get(ID);

if (stu == null) {

System.out.println("input student's name:");

String name = console.next();

Student newStudent = new Student(ID, name);

students.put(ID, newStudent);

System.out.println("成功添加:" + students.get(ID).name);

i++;

} else {

System.out.println("已经存在ID再输:");

continue;

}

}

testKeySet();

}


public void testKeySet() {

Set<String> keySet = students.keySet();

for (String stuId : keySet) {

Student stu = students.get(stuId);

if (stu != null) {

System.out.print(stu.name);

}


}

}


public static void main(String[] args) {

MapTest mt = new MapTest();

mt.mapAdd();

}

}

请输入学生ID:

1

input student's name:

tom

成功添加:1

请输入学生ID:

2

input student's name:

jay

成功添加:2

请输入学生ID:

3

input student's name:

jack

成功添加:3

123


正在回答

1 回答

解决了~

0 回复 有任何疑惑可以回复我~
#1

慕码人7051976

咋解决的倒是说啊
2019-11-30 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么输出的是key值?哪位大佬告诉我哈

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号