Sorting algorithm in java.