You can use an ArrayList
and then use the get(index)
for peekAt()
and remove(index)
for popAt()
functionalities. Also, you can sort you ArrayList
using Collections.sort()
and in case the elements of the ArrayList
are going to be your custom class objects, you can sort them by providing your own customer comparator.
Normal sort:
Collections.sort(list);
Custom sort:
public class MyComparator implements Comparator<MyClass>{
@Override
public int compare(MyClass o1, MyClass o2) {
// Your comparison logic
}
}
...
Collections.sort(list, new MyComparator());