For example we have the object created with the class that contain id, name and salary. The objects is posted by the salary and names if the salary is the same. What to do. We could not use indexes in arraylist. New for operator display only the whole set. But i need for example the 5 first element and 3 lasts?