Java: BETTER way to traverse a map

While reviewing the findbugs report (WMI_WRONG_MAP_ITERATOR) for a new project at work, I learned a better way to traverse a map in Java. In fact, since the first day I started coding in Java, I never thought twice about how to traverse a map. You always traverse the keys and use the key to get the value of the map.

for (Key key : map.keySet()) {
	Value value = map.get(key);
}

However, comes to think of it, it’s such a no-brainer. Every time you call map.get(key) you pay the price of the lookup. Since you need EVERY ELEMENT in the map, why look it up? Just get all of them like this:

for(Map.Entry mapEntry : map.entrySet()) {
	Key key = mapEntry.getKey();
	Value value = mapEntry.getValue();
}

That’s how jstl works. I just never paid attention. Better know it late than never :)

Eclipse CVS show history tags column stretched out

Gosh, I managed to double click on the show history tags column one time viewing a file that has gazillion tags. That stretched the tags column out of its capacity. There seems to be no way at least in UI to get that back to normal size so I can see the columns to the right of the tags column. I searched around and finally found a way to fix that without having to create a new workspace.

eclipes show history tags column stretched out

To Fix It:

starting from your workspaces folder, where “ProjectName” is the workspace you are having problems with.

\Workspaces\ProjectName\.metadata\.plugins\org.eclipse.team. cvs.ui\

open dialog_settings.xml

search for

"org.eclipse.team.internal.ccvs.ui.CVSHistoryTableProvider"

there is a tag in this section called “COL_TAGS.” That is the size of the tags column in the history view.