IdentityHashMap
传统的Map类型例如HashMap,在存储相同key值的数据的时候,之后存储的数据会把之前存在数据覆盖,保证Map中只有一个key值存在。例如:
HashMap<String,String> map = new HashMap<>();
map.put("1","A");
map.put("1","B");
System.out.println(map);
最后输出的结果是"1":"B"
但是IdentityHashMap的特性可以保存属于自己的key值,这个key值可以和其他的key值“相同”。例如:
IdentityHashMap<String,String> map = new IdentityHashMap();
map.put(new String("1"),"A");
map.put(new String("1"),"B");
System.out.println(map);
输出的结果是"1":"A","1":"B"
例子:
//IdentityHashMap形式通过创建对象的形式添加key值,可以保证在map中存入重复的key
IdentityHashMap<String,String> map = new IdentityHashMap();
//遍历实体类型集合,分别key和value赋值给map的key和value,用new对象的形式
for (QuestionParameterModel parameter : questionParameter) {
map.put(parameter.getKey(),parameter.getValue());
}
System.out.println(map);
//通过学生登录的手机号查询对应的cookie
UserEntity userEntity = userDao.selectuserbycode(studentId);
//发送请求
String response = HttpUtilsFormData.doPost1(HttpUrlConstant.POST_QUESTION,userEntity.getCookie(), map);
System.out.println(response);