The previous() method in Java is a part of the ListIterator interface, which allows bidirectional traversal of elements in a list. It moves the cursor one step backward in the list and returns the previous element in the sequence.
Syntax
public E previous()
- Parameters: No parameters.
- Return Type: Same type as list elements (e.g., String, Integer).
- Return Value: Returns the previous element and moves the cursor one step backward.
Example: Using previous() in ListIterator
import java.util.*;
public class GFG {
public static void main(String[] args)
{
List<String> animals
= Arrays.asList("Dog", "Cat", "Elephant");
ListIterator<String> listItr
= animals.listIterator(animals.size());
System.out.println("Backward Traversal:");
while (listItr.hasPrevious()) {
System.out.println(listItr.previous());
}
}
}
Output
Backward Traversal: Elephant Cat Dog
Explanation
- The listIterator(animals.size()) method positions the cursor after the last element for backward traversal.
- The hasPrevious() method checks if a previous element exists in the list.
- The previous() method returns the previous element and moves the cursor one step backward.
- The loop continues until the cursor reaches the beginning of the list.
Working of previous() Method
The previous() method retrieves the element that exists before the current cursor position and then moves the cursor backward. To understand how previous() works, let’s take a list containing “Apple”, “Banana”, and “Cherry”.
Step 1: After Forward Traversal
- Cursor lies after the last element.
- hasPrevious() -> returns true (since "Cherry" exists behind).
- Calling previous() returns "Cherry" and moves the cursor before Cherry.

Step 2: After Fetching “Cherry”
- Cursor lies between Banana and Cherry.
- hasPrevious() -> returns true (since "Banana" exists behind).
- Calling previous() returns "Banana" and moves the cursor before Banana.

Step 3: After Fetching “Banana”
- Cursor lies between Apple and Banana.
- hasPrevious() -> returns true (since "Apple" exists behind).
- Calling previous() returns "Apple" and moves the cursor before Apple.

Step 4: After Fetching “Apple”
- Cursor lies before the first element.
- hasPrevious() -> returns false (no elements behind).
- Backward iteration ends because the start of the list is reached.

previous() vs next()
| Feature | next() | previous() |
|---|---|---|
| Direction | Moves forward in the list | Moves backward in the list |
| Interface | Available in Iterator and ListIterator | Available only in ListIterator |
| Applicable To | All collections | Only list-based collections |
| Cursor Movement | Moves cursor one step forward | Moves cursor one step backward |