Array of object size Grow when Sorting in JAVA
<p>Hi I need to compare objects in a List with Java.
The list contain object named Place. I need the make an ascending sort with the distance (Integer) property of the Place object.</p>

<p>My objet class (Place) implement Comparable interface.</p>

<p>The problem (I think) is with the compareTo function :</p>

<pre><code>@Override
public int compareTo(Place place) {  
      if (this.distance &gt; place.distance)
         return 1;
      if (this.distance &lt; place.distance)
         return -1;
      else
         return 0;
}
</code></pre>

<p>Sometimes when I sort the array, the Array size grow. And I can't explain that?</p>

<p>The method they call Collections.sort() method :</p>

<pre><code>public static Place[] getPlaceForKey(Integer key){

    List&lt;Place&gt; places =  placesForCat.get(key);
    Collections.sort(places);
    return places.toArray(new Place[places.size()]);
}
</code></pre>

<p>Thanks</p>
