import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class ListIteratorExample { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("John"); list.add("Ringo"); list.add("George"); list.add("Paul"); ListIterator listIterator = list.listIterator(); /* * hasNext() returns true if this list iterator has more elements * when traversing the list in the forward direction. */ while (listIterator.hasNext()) { /* * next() returns the next element in the list * and advances the cursor position. */ System.out.println(listIterator.next()); } /* * hasPrevious() returns true if this list iterator has more elements * when traversing the list in the reverse direction. */ while (listIterator.hasPrevious()) { /* * previous() returns the previous element in the list * and moves the cursor position backwards. */ System.out.println(listIterator.previous()); } } }
$ java ListIteratorExample John Ringo George Paul Paul George Ringo John
ArrayList ListIterator example Iterate through elements Java ArrayList using ListIterator Example ListIterator in Java example Get previous and next index using Java ListIterator
Add Contents Of One ArrayList to Another
Array Of ArrayLists
ArrayList Adding Elements
ArrayList Remove Elements
ArrayList Remove Elements By Name
Basic HashMap Example
Basic HashSet Example
Basic TreeSet Example
Binary Search On Array
Calculate The Intersection Of Two Sets
Clone An ArrayList
Cosequential Processing
Count Duplicated Items In A List
Count Unique Characters In A String
Double Ended Queue
Find Minimum and Maximum Element in a Set
Finding The Longest String In A String Array
Initialize An ArrayList
Iterate Through A HashMap
Iterator Example
ListIterator Example
Parallel Arrays
Populate List With Comma Seperated Sting
PriorityQueue Sorted By String Length
Read Elements From A HashSet Using An Iterator
Read Elements From An ArrayList Using An Iterator
Simple Way To Print The Contents Of An Array
Sort An ArrayList Using A Comparator
Sorting A HashMap Using A TreeMap
Sorting A List Of Objects By Date
Stack Example
Swap Two Elements In An ArrayList