Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: ListIterator with LinkedList to search a value .. I want to modify code to do that?

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    23
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default ListIterator with LinkedList to search a value .. I want to modify code to do that?

     
     
    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 .


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Picture blurred to nitida in the profile...search code!
    By qaz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 18th, 2012, 11:21 AM
  2. Graph Search Theory with extend of BFS, UFS and A* Search in grid
    By keat84 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 7th, 2012, 09:46 AM
  3. Search class file for particular code
    By farooqshaik2010 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 3rd, 2011, 07:36 AM
  4. Need help fixing Binary Search Tree code
    By fistpunch in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 6th, 2010, 11:22 AM
  5. Help with ListIterator
    By vluong in forum Collections and Generics
    Replies: 5
    Last Post: October 16th, 2009, 09:33 AM

Tags for this Thread