next() Method in Java Collections Last Updated : 28 Oct, 2025 Comments Improve Suggest changes Like Article Like Report The Iterator and ListIterator interfaces provide the next method. It is used to retrieve the next element in a collection while traversing through it. It returns the next element in the iteration and moves the cursor forward by one position.Syntaxpublic E next()Return type: Same as collection, such as ArrayList, LinkedList, etc.Return value: The next element in the iteration.Exception: Throws NoSuchElementException if the iteration has no more elements.Example 1: Using next() in Iterator Java import java.util.*; public class GFG{ public static void main(String[] args) { List<String> fruits = Arrays.asList("Apple", "Banana", "Cherry"); Iterator<String> iterator = fruits.iterator(); // checks if element exists while (iterator.hasNext()){ // fetches next element String fruit = iterator.next(); System.out.println(fruit); } } } OutputApple Banana Cherry ExplanationThe iterator() method returns an Iterator for the list.The hasNext() method checks if another element exists.The next() method retrieves the next element and advances the cursor.The loop continues until no elements remain.Example 2: Using next() in ListIterator Java 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(); System.out.println("Forward Traversal:"); while (listItr.hasNext()) { System.out.println(listItr.next()); } } } OutputForward Traversal: Dog Cat Elephant ExplanationThe listIterator() method returns a ListIterator for the list.The hasNext() method checks if another element exists in the list.The next() method retrieves the next element and moves the cursor forward.The loop continues until all elements in the list are traversed.Working of next() MethodThe Iterator cursor does not point directly to an element, but rather lies between elements. To understand how next() works, let’s take a list containing “Apple”, “Banana”, and “Cherry”.Step 1: Before IterationThe cursor lies before the first element.hasNext() -> true (since the next element exists).Calling next() returns "Apple" and moves the cursor after Apple.outputStep 2: After Fetching “Apple”Cursor lies between Apple and Banana.hasNext() -> true.Calling next() returns "Banana" and moves the cursor after Banana.outputStep 3: After Fetching “Banana”Cursor lies between Banana and Cherry.hasNext() -> true.Calling next() returns "Cherry" and moves the cursor after Cherry.outputStep 4: After Fetching “Cherry”Cursor now lies after the last element.hasNext() -> false.Iteration ends because no more elements exist.outputIterator.next() vs ListIterator.next()FeatureIterator.next()ListIterator.next()DirectionForward onlyForward and backward (with previous())InterfaceIteratorListIteratorApplicable ToAll collectionsOnly list-based collectionsCursor PositionMoves forwardMoves forward and can move back Create Quiz Comment V vishnucg6ix Follow 0 Improve V vishnucg6ix Follow 0 Improve Article Tags : Java Java-Iterator Java-Collectors Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like