What would be a good list structure to use when I want to loop trough it and back again and so on? I’m now using a extended ArrayList with a custom method for looping it forward and backward etc.
Does Java (Android) offer a list type that I can use without extending it’s behavior?
If not, what would be the best way to code a list for this use-case?
My current code looks a bit like this:
if(!back){
if(hasNext()){
return next();
} else {
back = true;
return previous();
}
} else {
if(hasPrevious()){
return previous();
} else {
back = false;
return next();
}
}
A
LinkedListis exactly what you’re looking for. It’s defaultiteratoris a forward iterator, but it also provides adescendingIterator