It's not a secret anymore!*
The moose likes Java in General and the fly likes ListIterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ListIterator" Watch "ListIterator" New topic
Author

ListIterator

R Jarman
Greenhorn

Joined: Feb 08, 2005
Posts: 27
I'm using a ListIterator to parse through an ArrayList. I understand how to use it to parse the entire array but what if I'm looking for something in the array? Once I find the object I want to do some processing on it and I don't want to parse the rest of the array. How can I punch out of an ListIterator once a condition has been met or am I better off using the old way with for loops or while loops?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Just don't call "next" anymore. Use "break" to escape out of your loop.


[Jess in Action][AskingGoodQuestions]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ListIterator
 
Similar Threads
Traversing an ArrayList
Convert int array to Vector
Reading array from file
printing...static context?
Arrays & loops