• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector Iteration

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
The loop below is running indefinetely even though the vector has a limited number (17) of elements in it.
Could you please advice as to why and how to do it right!?!
Any help is greatly appreciated!
Thank you!
Sergey
-----
while( gcVector.listIterator().hasNext() ){

System.out.print("*");

}
-----
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to do the following:
ListIterator iterator = gcVector.listIterator();
while( iterator.hasNext() ){
iterator.next();
System.out.print("*");
}

iterator.hasNext() does not advance the pointer. You have to do iterator.next() to advance the pointer.
Hope this help,
Payam.
 
Sergey Snovsky
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Payam!
Thanks a lot!!! -- Very helpful!
Sergey
 
reply
    Bookmark Topic Watch Topic
  • New Topic