In Java, I want to go through a list of elements and insert a new one at the right place. I was thinking of doing it in this way:
for( Tab tab : tabList )
if( newTab.getPriority() < tab.getPriority() ) {
newTab.insertBefore(tab);
break;
}
if( tab == null )
newTab.insertBefore(endMarker);
Unfortunately, tab is not accessible outside the for loop. Is there any simple way to do what I want or do I have to use a boolean?
It is better practice to use a
tabvariable outside the scope of theforloop