Run ❯
Get your own Java server
❯Run Code Ctrl+Alt+R
Change Orientation Ctrl+Alt+O
Change Theme Ctrl+Alt+D
Go to Spaces Ctrl+Alt+P
import java.util.LinkedList; import java.util.ListIterator; public class Main { public static void main(String[] args) { // Make a collection LinkedList
cars = new LinkedList
(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); // Get the iterator ListIterator
it = cars.listIterator(); // Loop through the list while(it.hasNext()) { System.out.println(it.next()); } System.out.println("---"); // Loop backwards through the list while(it.hasPrevious()) { System.out.println(it.previous()); } } }
Volvo
BMW
Ford
Mazda
---
Mazda
Ford
BMW
Volvo