This Java Example shows how to Iterate through the element of the LinkedList object in java.
IterateThrough Element Using Iterator Java LinkedList Example
This Java Example shows how to Iterate through the element of the LinkedList object in java. To iterate the LinkedList object we use hasNext() and next() methods of Iterator to iterate through the elements.
Example: IterateThroughElementLinkedList.java
package devmanuals.com;
import java.util.*;
public class IterateThroughElementLinkedList {
public static void main(String[] args) {
LinkedList LKLST = new LinkedList();
LKLST.add("Gyan");
LKLST.add("Singh");
LKLST.add("Arunesh");
LKLST.add("Kumar");
Iterator itr = LKLST.iterator();
System.out.println("The LinkedList Elements are : ");
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
}
Output:
| The LinkedList Elements are :
Gyan Singh Arunesh Kumar |

[ 0 ] Comments