package Map;/** *学生类 */public class student { private String xingbie; private String nome; public String getXingbie() { return xingbie; } public void setXingbie(String xingbie) { this.xingbie = xingbie; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } public student(String xingbie, String nome) { super(); this.xingbie = xingbie; this.nome = nome; } public student() {}; public void zbai () { System.out.println(nome+"性别是:"+xingbie); } }
package Map;/** * 测试类 */import java.util.*;public class studentDome { public static void main(String[] args) { student s1 = new student("男","李四"); student s2 = new student("女","小七"); Mapm = new HashMap (); m.put("LS", s1); m.put("XQ", s2); Set s = m.keySet(); for(String ss:s) { student a=m.get(ss); System.out.println(ss+a.getXingbie()+a.getNome()); } }}
输出结果图:
代码下载链接:
链接:https://pan.baidu.com/s/1aCjHFn807YTylPk4r5_vNA
提取码:siqs