java题有一句不懂

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:12:01
import java.util.*;

class student{
HashMap stu;
student(){
stu=new HashMap();
}

void add(){
stu.put("张三",new Integer(99));
stu.put("李四",new Integer(80));
}

void display(String name){
Integer sorc=(Integer) stu.get("张三");\\这句话什么意思

System.out.println (name+sorc.intValue());
}

void display1(String name){
Integer sorc=(Integer) stu.get("李四");\\这句话什么意思
System.out.println (name+sorc.intValue());
}

void updatestudent(String name,Integer sorc){
stu.put(name,sorc);
}
}

class hp{
public static void main(String [] args){
student s= new student();
s.add();
s.display("张三");
s.display1("李四");
s.updatestudent("李四",90);
s.display("张三");
s.display1("李四");
}

Integer sorc=(Integer) stu.get("李四");
取hashmap中的与李四相对应的key值,并强制转换为整型。

HashMap stu;
Integer sorc=(Integer) stu.get("李四");\\这句话什么意思

查看hashmap说明吧。。。

hashmap是将键和值对应起来存储在hashmap对象中
stu.put("张三",new Integer(99)); 就是存储的过程,其中“张三"是键,new Integer(99)是值
Integer sorc=(Integer) stu.get("张三");
的意思也就是得到键"张三"对应的值new Integer(99),再将其赋给sorc

Integer sorc=(Integer) stu.get("李四");
取hash表的'李四'信息整型(数字)值80 赋值给整型(数字)变量 sorc

另外一个同理