ListIterator with LinkedList to search a value .. I want to modify code to do that?
Code :
package javaapplication2;
import java.util.*;
public class MainClass {
public static void main(String[] args) {
LinkedList <Integer> IntegerNode = new LinkedList<Integer>();
int node1 = 1;
int node2 = 5;
int node3 = 10;
int node4 = 13;
int node5 = 17;
int node6 = 20;
int size;
Iterator iterator;
IntegerNode.add(node1);
IntegerNode.add(node2);
IntegerNode.add(node3);
IntegerNode.add(node4);
IntegerNode.add(node5);
IntegerNode.add(node6);
ListIterator<Integer> listIter = IntegerNode.listIterator( );
while(listIter.hasNext())
{
System.out.println(listIter.next());
}
}
}
I want to write some code that search a specific value from the linked list,,, for example 10,, I don't care what is the possible printed or returned value. whether it is the index or the value itself. Ok I just want to search it somehow, I am not confined to ListIterator .
Re: ListIterator with LinkedList to search a value .. I want to modify code to do tha
The iterator class has a method that returns the next item from the list. The code is using it in the println().
Given the next item, Then use an if statement to test for the specific value you are looking for.