title: Fastest way to sort an array of objects in java
body: <p>I have a Class called apple which contains 3 values as <code>int x</code>, <code>int y</code> and <code>int weight</code>. Then i created an array of apple type objects. Now i want to sort the the array of objects based on weight meaning the the apple object with the lowest weight should be first and so on.</p>
  
  <p>I know there are quite a few ways to achieve this by using Arrays.sort etc or comparators. </p>
  
  <p>I was wondering what is the fastest way of doing this sort in Java? There can be a case where i have 500,000 objects so i want to know which sort i should use, more importantly which approach will give me best approach. i have even wrote my own quick sort with Hoare partition. </p>
  
  <p>Code for Apple class</p>
  
  <pre><code>public class Apple {
      public int x;
      public int y;
      public int weight;
  
      public Apple(int a, int b, int w) {
          x = a;
          y = b;
          weight = w;
      }
  }
  </code></pre>
  
  <p>Code for main class</p>
  
  <pre><code>public class main {
      static Apple[] appleArray;
  
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int size = sc.nextInt();
          int totalApples = sc.nextInt();
          appleArray = new Edge[totalApples];
          int x = 10;
          int y = 20;
          int w = 30;
  
          for (int i = 0; i &lt; size; i++) {
              appleArray[i] = new Apple(x, y, w);
              x++;
              y++;
              w++;
          }
          //Now i want to sort array of apple objects based on weight
      }
  }
  </code></pre>