java - Why do the same values get put into my LinkedHashMap Array? -
i using linkedhashmap
array. way 'put' , 'get' values?
in linkedhashmap<integer, integer[]>
have:
key 1 -> integer array
{5,6,2,4}
key 2 -> integer array,
{7,2,6,1}
.... goes on
here code snippet use store values
// has store data order received linkedhashmap<integer, integer[]> hparamval = new linkedhashmap<integer, integer[]>(); // temprory integer array store number received integer[] iarrynoofparam = new integer[inoofscalar]; (irow = 0; irow < inoofblocks; irow++) { (icol = 0; icol < inoofarrval; icol++) { bbuffgenstr = arrays.copyofrange(buffrecv, istartloc, ioffset); gendataval oparamval = datastruct.readgenvalue(bbuffgenstr); bbuff4genstr = oparamval.getvalue(); // store integer array received iarrynoofparam[icol] = bytebuffer.wrap(bbuff4genstr) .order(byteorder.little_endian).getint(); istartloc = ioffset; } // store array of integer every key hparamval.put(irow, iarrynoofparam); }
is hparamval.put
correct?
the following code data linkedhashmap
for (integer key : hloadsurveyparam.keyset()) { system.out.println(" key # " + key); (icol = 0; icol < inoofscalar; icol++) { system.out.println(hparamval.get(key)[icol]); } }
is hparamval.get
correct of above?
i getting same value, because last values stored in iarrynoofparam
keys!
bring line integer[] iarrynoofparam = new integer[inoofscalar];
for
loop.
when call put()
storing reference of array in linkedhashmap. since storing same reference every time, see values set last. want store new array reference every key in linkedhashmap.
Comments
Post a Comment