Implemented method to collect elements in a sorted list