Answer

Here's the answer to the above question.

In the code that adds the hash values:

v[0]=i;v[1]=j;
result.put(i+ ","+j, v);

each iteration the object v is added to the HashMap result. (in Java, with technicality, arrays are objects.) In each iteration the array's values are changed, however, The result seems to contain all identical arrays.

The intended program should have the array declaration inside the loop like this:

int[] v= newint[2];
v[0]=i;v[1]=j;
result.put(i+ ","+j, v);

or the simpler syntax irregularity

int[] v= {i,j};
result.put(i+ ","+j, v);

so that in each iteration a new object is added as the value to the hash key.

(thanks to people in Yahoo and Sun Microsystem's Java forums for answer to the question.)

The behavior Java the lang exhibited above, is that in most imperative languages, they represent some underlying models based on hardware, as opposed to a mathematical interpretation of the code. So in the above, v represent some mystic “object” thingie behind the scenes. Even though ostensibly its value is changed and placed into the list in each iteration, but that's not what it seems.