1 Replies - 794 Views - Last Post: 01 April 2011 - 10:31 PM Rate Topic: -----

#1 gamarays123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-March 11

How do i print LinkedList using ListIterator

Posted 01 April 2011 - 10:05 PM

I am using LinkedList from the API, but I can't print it.
This is what I did:
private LinkedList<String> text ;// list
 private ListIterator<String> current = null;// the iterator 
.
.
.
.
.
.
// and my display method

public void display()
{
   while(current.hastNext())
   {
    System.out.println(current.next());
   }
}
//when I run it, i get this message:
//Exception in thread "main" java.util.ConcurrentModificationException
       // at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:761)
        //at java.util.LinkedList$ListItr.next(LinkedList.java:696)





Is This A Good Question/Topic? 0
  • +

Replies To: How do i print LinkedList using ListIterator

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: How do i print LinkedList using ListIterator

Posted 01 April 2011 - 10:31 PM

Your code for the iteration is correct yet are you sure you set the LinkedList for your ListIterator? you should have something like this: ListIterator<String> current = text.listIterator(); plus make sure you populate your linked list with some data. Good luck :)

This post has been edited by ayman_mastermind: 01 April 2011 - 10:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1