Added Comments and changed the sorting method to Collections.sort
because of the performance.