1 package com.twister;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5
6 public class Points implements Comparable<Points>{
7 int xCoordinate;
8 /*
9 * 1. Returns 0 if both points have same xCoordinate (say 3 & 3) - returns 3-3=0
10 * 2. Returns +ve if first point is on the
11 * right hand side of the second point (say 5, -3) - returns 5 - (-3) = 8
12 * 3. Returns -ve if first point is on the
13 * left hand side of the second point (say -5, 3) - returns (-5) - (3) = -8
14 */
15 public int compareTo(Points p) {
16 return xCoordinate - p.xCoordinate;
17 };
18
19 public static void main(String[] args) {
20 ArrayList<Points> arrPoints = new ArrayList<Points>();
21 /* Add lots of points to the array list */
22 Collections.sort(arrPoints);
23 /*Print the sorted collection */
24 }
25 }