首页 > 其他 > 详细

根据学员英文名找到学员对象

时间:2019-07-28 00:34:43      阅读:128      评论:0      收藏:0      [点我收藏+]

学生类

 

package com.twod1z;
/**
* @program: com.twod1z
* @description:根据学员英文名找到学员对象(学生类)
* @author: Mr.Lin
* @create: 2019年7月27日
**/
public class Student {
private String name;
private char sex;

public Student() {}

public Student(String name, char sex) {
this.name = name;
this.sex = sex;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public char getSex() {
return sex;
}

public void setSex(char sex) {
this.sex = sex;
}


}

   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

测试类

package com.twod1z;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @program: com.twod1z
* @description:根据学员英文名找到学员对象(测试类)
* @author: Mr.Lin
* @create: 2019年7月27日
**/
public class Text {
public static void main(String[] args) {
Student s1 = new Student("张明",‘男‘);
Student s2 = new Student("李欣",‘女‘);
Student s3 = new Student("王武",‘男‘);

Map<String,Student>m = new HashMap<String,Student>();

m.put("Jack", s1);
m.put("Mary", s2);
m.put("Michael", s3);

Set<String>s = m.keySet();

for (String str : s) {
Student stu = m.get(str);
System.out.println(str+"对应的学员姓名是:"+stu.getName()+";性别是:"+stu.getSex());
}
}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

技术分享图片

 

根据学员英文名找到学员对象

原文:https://www.cnblogs.com/lpbk/p/11257064.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!