title: Adding a list of elements to a linked list
body: <p>I'm developing an android application with google maps.
  I have created a hashmap which stores Lat/Lng,Float in it.</p>
  
  <pre><code>Map&lt;LatLng,Float&gt; distance_Map = new HashMap&lt;LatLng, Float&gt;();
  </code></pre>
  
  <p>I use this to store distance between 2 given latitude and longitude using following method.</p>
  
  <pre><code>Location loc1 = new Location("");
          loc1.setLatitude(markerPoints.get(0).latitude);
          loc1.setLongitude(markerPoints.get(0).longitude);
  
          Location loc2 = new Location("");
          loc2.setLatitude(markerPoints.get(i).latitude);
          loc2.setLongitude(markerPoints.get(i).longitude);
  
          float distance = loc1.distanceTo(loc2);
  
          distance_Map.put(markerPoints.get(i), distance);
  </code></pre>
  
  <p>So I run this code through a loop and find distances between the first place user enters and the other places and stores the corresponding distances and Lng/Lat in the distance_Map.After that I use the following code to sort these distances.</p>
  
  <pre><code>List&lt;Map.Entry&lt;LatLng,Float&gt;&gt; sorted_Distance_LatLng_List = new LinkedList&lt;Map.Entry&lt;LatLng, Float&gt;&gt;(distance_Map.entrySet());
              Collections.sort(sorted_Distance_LatLng_List, new Comparator&lt;Map.Entry&lt;LatLng, Float&gt;&gt;() {
                  @Override
                  public int compare(Map.Entry&lt;LatLng, Float&gt; o1, Map.Entry&lt;LatLng, Float&gt; o2) {
                      return o1.getValue().compareTo(o2.getValue());
  
                  }
              });
  </code></pre>
  
  <p>This runs perfectly.But I need to use the same linkedlist sorted_Distance_LatLng_List to sort another set of distances.To do that I use the same hashmap (distance_Map) by clearing its values.</p>
  
  <pre><code>distance_Map.clear();
  distance_Map.put(markerPoints.get(i), distance);
  </code></pre>
  
  <p>but I do not know how to insert this distance_Map to the same LinkedList(sorted_Distance_LatLng_List).I use the following code</p>
  
  <pre><code>sorted_Distance_LatLng_List.clear();
  
                  List&lt;Map.Entry&lt;LatLng,Float&gt;&gt; sorted_Distance_LatLng_List = new LinkedList&lt;Map.Entry&lt;LatLng, Float&gt;&gt;(distance_Map.entrySet());
                  Collections.sort(sorted_Distance_LatLng_List, new Comparator&lt;Map.Entry&lt;LatLng, Float&gt;&gt;() {
                      @Override
                      public int compare(Map.Entry&lt;LatLng, Float&gt; t1, Map.Entry&lt;LatLng, Float&gt; t2) {
                          return t1.getValue().compareTo(t2.getValue());
                      }
                  });
  </code></pre>
  
  <p>But it gives me the error, because the list is already created. How can I do it?Please help me.Thank you in advance.</p>