Click here to Skip to main content
15,663,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do i stop this method examing any more matches in the collection once its found a match

What I have tried:

<pre>public void setAvailability(int identity, int location, boolean available)
        Iterator<Assistant> it = assistants.iterator();
            Assistant assistant =;
            if(identity == assistant.getIdentity()){
                if(available == true){
                else {
Updated 21-Nov-22 20:29pm

Use a break statement:

Java Break and Continue[^]
Share this answer
Freddie Francis 21-Nov-22 16:45pm    
sorry, but i cannot include a break statement inside the loop, i need another way
Dave Kreskowiak 21-Nov-22 18:47pm    
Then you're going to have to create a boolean flag that you initialize to true, and that you set to false when you want to exit the while loop. You'll have to change the condition expression in the while statement to check the flag AND hasNext.
k5054 21-Nov-22 18:14pm    
Why not? It's a perfectly valid way of ending a loop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900