title: How To Sort Through An array from type "NameOfClass"
body: <p>I have a Program that finds The Maximum distance between a pair of Points:
  This is class Point:</p>
  
  <pre><code>public class Point {
  
    private int x;
    private  int y;
    public Point (int a, int b) {
        x=a; y=b;
    }
    public double distance (Point p){
      int tempx , tempy;
      tempx=(x-p.x)*(x-p.x);
      tempy=(y-p.y)*(y-p.y);
      return  Math.sqrt(tempx+tempy);
    }
    public void show(){
        System.out.println("(" + x + "," + y + ")");
    }
  }
  </code></pre>
  
  <p>And This is The Main Program:</p>
  
  <pre><code>public static void main(String[] args) {
      // TODO Auto-generated method stub
      Point[] allPoints=new Point[5];
        int k=0;
        int rx,ry;
        while (k&lt;=allPoints.length-1){             
        rx=(int)(1+Math.random()*10);               
        ry=(int)(1+Math.random()*10);
        allPoints[k]=new Point(rx, ry);
        k++;
        }
  
        int i,j,mi,mj;
        double mDis=0,cDis;
        mi=mj=0;
        i=0;
        while ( i&lt;allPoints.length-1) {
          j=i+1;
          while (j&lt;allPoints.length) {
            cDis= allPoints[i].distance(allPoints[j]);
            if (cDis&gt;mDis){
            mDis=cDis; 
            mj=j; 
            mi=i;}
            j++;
           }    
           i++;
          }
  
        allPoints[mj].show();
        allPoints[mi].show();
          System.out.print("max dis is " + mDis +" first point: " + mi + " second point: " + mj);
  } 
        //////////
  
  
  }
  </code></pre>
  
  <p>As You Can see the program has an array with 5 "Cells" and it finds the pair with the Maximum distance, I wanted to know how I could change the program so that it would sort and print the points according to the distance between them.
  for Example: Point1: 2,2 Point2: 6,6 Point3: 1,1
  So The distance between Point3 and Point 1 is the smallest so The program should output: 1,1 2,2 6,6
  the reason why 6,6 would be last because the distance between 6,6 and 2,2 is the greatest, Im new in Java so it would be a great help if you could explain it to me.</p>