For now, you can always iterate over your ArrayList using an index, for example
List<String> myList = new ArrayList<String>(); ... add code to populate the list with some data... for (int i = myList.size() - 1 ; i >= 0 ; i--) { if (myList.get(i).equals("delete me")) { myList.remove(i); } }
you would be better off using ListIterator<T> to remove items from your ArrayList :
ListIterator<String> listIter = myList.listIterator(); while (listIter.hasNext()) { if (listIter.next().equals("delete me")) { listIter.remove(); } }
List iterators can be used to iterate your list backwards - for example:
ListIterator<String> listIter = myList.listIterator(myList.size()); while (listIter.hasPrevious()) { String prev = listIter.previous();
The starting index of the iterator must be equal to the index of the last element + 1. As the docs say: "An initial call to previous will return the element with the specified index minus one."
source share