在起始散列表中包含key(String)和value(ArrayList)。在运行以下代码一段特定时间之后,在每次更新中,每个密钥都会使用相同的ArrayList进行更新。这是代码:
int c=0;
ke=location.keys();
value=new ArrayList<String>();
System.out.println("Before operation: "+value.size());
while(ke.hasMoreElements() && c==0)
{
//System.out.println("Start value Size: "+value.size());
String hKey=ke.nextElement();
String spl[]=hKey.split(", ");
Double kLat=Double.parseDouble(spl[0]);
Double kLon=Double.parseDouble(spl[1]);
if(haversine(lat, lon, kLat, kLon)<=30)
{
count++;
c=1;
value.clear();
value=location.get(hKey);
location.remove(hKey);
value.add(lat+", "+lon);
if(spl.length==2)
{
ky++;
hKey=hKey+", "+timedate;
}
else
hKey=kLat+", "+kLon+", "+timedate;
location.put(hKey, value);
System.out.println();
break;
}
}