Java:HashMap storing same value as key and value.?

I am getting this strange output in `HashMap`. I have two `ArrayList` one containing the key and another containing value. My `HashMap` will store only string as key and value pair. But key itself is getting stored in value. I have checked my value arraylist, it's printing the value. But during putting it's setting it as key itself. Code snippet is: public HashMap getLstBarring() { ArrayList temparrLst=setPreParameters(fetchPreDetails, 1); System.out.println("KEY" + temparrLst); ArrayList tempArrLstId=setPreParameters(fetchPreDetails, 14); System.out.println("VALUE" +tempArrLstId); int length=tempArrLstId.size(); for(int index=0;index>>>>>>>>>>>>>" + lstBarring); return this.lstBarring; } Problem is: - 1st SOP is KEY-printing all the key correctly. - 2nd SOP is VALUE-printing all the value correctly. - 3rd SOP is VALUE IN KEY----printing all the values. - 4th SOP is VALUE IN VALUE--printing all the values. Hence after ever iteration I am getting value,value in `HashMap` whereas it should be key,value. Here's look at my Method:- public ArrayList setPreParameters(HashMap fetchPreDetails,int index) { switch(index) { case 1: { arrLstData.clear(); splittedString=fetchPreDetails.get(1).split(","); Collections.addAll(arrLstData, splittedString); break; } return arrLstData; Please guide me as to where am I going wrong.
I wonder what the second (numeric) parameter in setPreParameters does mean? Why is it different (1 vs 14)?

以上就是Java:HashMap storing same value as key and value.?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准