Little help understanding HashMap
I'm trying hasmaps for the first time, and I have a question please.
I have a class, called Trac. That class is string information about gps coordinates for a vehicle.
HashMap<Long,Track> trackMap = new HashMap<Long,Track>();
I open up a text file, which has a vehicle ID and it latitude and longitude.
As you can see from the code below, I create a new Track object for each vehicle that is in the list. Each list can contain the same vehicle multiple times, but each entry has different longitude and latitude.
If the Track object isn't in the hashmap, then it adds it to it. If it's already in the hashmap, it just skips it.
Let's say that the only thing in the Track class is a variabled called Point2D.Double LatLong. My question is, how can I update the Track that is stored in the hashmap to reflect the new LatLong if I find the same vehicle ID with newer coordinates. I know one way would be this.
if(trackMap.containsValue(cellId)){
trackMap.remove(cellId);
}
else{
trackMap.put(cellId,testTrack);
}
As you can see, if it finds it in the trackMap hashmap, it simply deletes it, then stores the newer one. However, I was told this can be very expensive.
Is there a way that I can just update trackMap, instead of deleting and then re-adding it?

