我想知道对于声明如下的 HashMap
:
static HashMap<Integer, Integer> test= new HashMap<>();
当我们使用 test.get(i)
时,哪个整数值是键,哪个整数值将作为结果返回?
for(int k=0;k<Array.size();k++)
{
test.put(k,0);
}
for(int i=0;i<NUM;i++)
{ test.replace(temp.get(i)), occurence.getOrDefault(stringToint.get(featurename), tempp.get(withThis))+1);
}
最佳答案
static HashMap<Integer, Integer> test= new HashMap<>();
Integer i = 3;
test.put(3, 6); //key -> 3, value -> 6
Integer result = test.get(i);
那么,结果
将为6。3是键,6是与该键关联的值。请注意,首先,您必须设置任何键/值对,否则您将得到 null
。
关于java - 如果使用 get() 将返回 HashMap<Integer,Integer> 的哪个键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471494/