Error Solved. Arraylist was wrongly used in sorting logic.