Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在<;类型的java中为map使用getValue方法;字符串,整数>;_Java_Maps_Typecasting Operator_Getvalue - Fatal编程技术网

在<;类型的java中为map使用getValue方法;字符串,整数>;

在<;类型的java中为map使用getValue方法;字符串,整数>;,java,maps,typecasting-operator,getvalue,Java,Maps,Typecasting Operator,Getvalue,执行以下部分时,getValue()方法中出现错误。我尝试在getValue()中将s作为参数传递。在那里也不起作用 //Mymap<String,Integer>() while(in.hasNext()){ //in is a scanner object String s = in.next(); // Write code here //s is a string to be searched if (Mymap.cont

执行以下部分时,
getValue()
方法中出现错误。我尝试在
getValue()
中将s作为参数传递。在那里也不起作用

//Mymap<String,Integer>()       
while(in.hasNext()){
    //in is a scanner object
    String s = in.next();
    // Write code here
    //s is a string to be searched
    if (Mymap.containsKey(s)) {
        //the value corresponding to s is to be retrieved
        Integer i= (Integer)Mymap.getValue();
        System.out.println(i);
        System.out.println(s+"="+Mymap.get(s));
    } else {
        System.out.println("Not found");
    }
}
//Mymap()
while(在.hasNext()中){
//中是扫描仪对象
字符串s=in.next();
//在这里写代码
//s是要搜索的字符串
如果(Mymap.containsKey){
//要检索与s对应的值
整数i=(整数)Mymap.getValue();
系统输出打印LN(i);
System.out.println(s+“=”+Mymap.get(s));
}否则{
System.out.println(“未找到”);
}
}

好的,正如其他人指出的,方法
getValue()
不存在,因此编译错误

HashMap类的所有方法

如果需要与键
s
对应的整数值并将其存储在
i
中,则应调用
Mymap.get(s)
。。。就像你在排队时做的那样:

System.out.println(s+"="+Mymap.get(s));

什么是
Mymap
getValue
在接口
Map
中不存在,它只存在于
Map中。Entry
在EntrySet@RouliboygetValue上迭代在Map接口上没有意义,它不存在。如果需要,可以迭代EntrySet。如果要获取特定键的值,请使用
Map.get
。但我不明白你试图用getValue做什么