Here’s the scenario:
- Loop through the list and for each slot
- Compare current value with the given value
- If match is found modify current item and break the loop
- If the given value wasn’t find in the loop add it to the list
Turns out breaking out of loops using labels also works for curly block of code so the solution is below
Listlist = getFromSomewhere(); Foo foo = whatever(); gotu: { for (Foo f : list) { if ( f.equals(foo)) { f.setBlah(foo.getBlah()); // blah is not used in compare() break gotu; } } // only want to execute the following if the loop was never broken list.add(foo); }
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.