title: Sorting an object array on a float value
body: <p>I'm beginning to learn Java. Currently I got stuck at sorting an array of Objects in ascending order of a float value in the object. Goal is to draw a Graph from the arrays of data. Before I can draw the graph I have to sort the coordinates so that the <code>x</code> values are ascending order. So I put them in an Object to link <code>x</code> and <code>y</code> data together.</p>
  <p>I'm starting with 2 arrays of floats:</p>
  <pre class="lang-java prettyprint-override"><code>float[] xValues = {-5.6f, 2.1f, 0.1f, 4.4f, 8.5f, -1.6f};
  float[] yValues = {1.0f, 2.4f, 5.7f, -2.8f, -6.4f, 2.9f};
  </code></pre>
  <p>Than I put  it into an Point object array using this function:</p>
  <pre class="lang-java prettyprint-override"><code>graphPoints = new Point[arrayLength];
  for (int i = 0; i &lt; graphPoints.length; i++) {
      graphPoints[i] = new Point();
  }
  
  for (int i = 0; i &lt; graphPoints.length; i++) {
      graphPoints[i].x = x[i];
      graphPoints[i].y = y[i];
  }
  </code></pre>
  <p>containing this object:</p>
  <pre class="lang-java prettyprint-override"><code>class Point {
      public float x;
      public float y;
  }
  </code></pre>
  <p>Possible solutions I found on the web suggest sorting the object array using a <code>comparator&lt;Point&gt;</code>, something I haven't learned yet. Using the examples I found could not get it to work with an float value. All examples work with either strings of int's.</p>
  <p>Am I missing something? Is there a proper way to do this? Who could give me some guidance on this topic?</p>