Java HashMap的哪个键<;整数,整数>;如果使用get()将返回

Java HashMap的哪个键<;整数,整数>;如果使用get()将返回,java,hashmap,Java,Hashmap,我想知道,对于声明如下的HashMap: static HashMap<Integer, Integer> test= new HashMap<>(); static HashMap test=new HashMap(); get(key)返回与输入键关联的值。如果您的输入是一个基本类型,在本例中为int,它将自动装箱到Integer类,您将获得相应的Integer键的值…在本例中它也是一个整数。static HashMap test=new HashMap();

我想知道,对于声明如下的
HashMap

 static HashMap<Integer, Integer> test= new HashMap<>();
static HashMap test=new HashMap();
get(key)返回与输入键关联的值。如果您的输入是一个基本类型,在本例中为int,它将自动装箱到Integer类,您将获得相应的Integer键的值…在本例中它也是一个整数。

static HashMap test=new HashMap();
static HashMap<Integer, Integer> test= new HashMap<>();

Integer i = 3;

test.put(3, 6); //key -> 3, value -> 6

Integer result = test.get(i);
整数i=3; 测试。放置(3,6)//键->3,值->6 整数结果=test.get(i);
然后,
结果将是6。3是键,6是与此键关联的值。请注意,首先,必须设置任何键/值对,否则将得到
null

类HashMap
Class HashMap<K,V>


Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
类型参数: K-此地图维护的密钥类型 V-映射值的类型
上面的解释是不言自明的,现在如果您有两种整数类型,您只需记住参数类型,它将与您使用的任何类型保持相同


您的意思是默认情况下第一个整数是键?是的。这是一个定义键到值映射的数据结构。第一部分是键,第二部分是值。在您的示例中,您在哪里设置了键?\checkout put()方法,它接受两个参数第一个是键,第二个是值,因此put(3,6)表示键=3,值=6
static HashMap<Integer, Integer> test= new HashMap<>();

Integer i = 3;

test.put(3, 6); //key -> 3, value -> 6

Integer result = test.get(i);
Class HashMap<K,V>


Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values