I would sort the list. Then I will create a list with these 10 smallest objects and list1 original list1 to contain the rest of the objects. Sort of:
Collection.sort(list1); ArrayList<Example> yourSmallestElements = (ArrayList<Example>)(list1.sublist(0, 9).clone()); list1.removeAll(yourSmallestElements);
NOTE. I cloned subscriptions because sublist() only returns a view of list1 , and that is not what you want here.
Your Example class can implement "Comparable" so that you can determine how to compare them. You will need to implement the compareTo() method. Something like that:
public class Example implements Comparable<Example> { private int integerVal = <a value>; public int compareTo(Example exampleObject) { return exampleObject.integerVal - this.integerVal; } }
Check out this link , or rather a class that starts as follows:
public class Fruit implements Comparable<Fruit>{
source share