How to iterate

The problem is ‘remove a certain item from a collection’.
If you remove an object and the counter keep going, you’re going to jump the next element.

The solution my predecessor come to:

	private void removeData(String code){
		String sp914code;
			
		for (int i = 0; i < sp914Codes.size(); i++){
			sp914code = sp914Codes.get(i).toString();
			if(sp914code.equals(code)){
				sp914Codes.remove(i);
				i=-1;
			}
		}
	}

Restart everytime from the very beginning, obvious.

I doesn’t dare touch this, even if I’d worked on that class, in THAT Big Bank

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s