Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug into a map?

Tags:

java

map

I sometimes had such a difficult situation in debugging. I have a Java HashMap which contains many entries, and the program doesn't work as expected because it says the map doesn't contain a particular entry, but that entry is supposed to be in the map. However, I can't debug into the map. In Eclipse I can see the internals of the Map in variables, but given so many entries it's hard to eye-scan all the entries in the map to see whether that entry is in the map or not.

Is there a better way to debug this type of situation? For you for your insight and thoughts.

like image 235
user697911 Avatar asked Mar 27 '14 23:03

user697911


1 Answers

Most debuggers allow you to evaluate an expression while sitting in a debug breakpoint, and Eclipse is no exception (see Eclipse help - Evaluating expressions). Just evaluate myMap.get(theKey) to see if the entry is in the map.

Another option is that most debuggers show the toString() value of an object in the Variables view. If the map doesn't have too many entries, you should be able to see all of the entries of the map there.

like image 146
Mark Peters Avatar answered Sep 29 '22 15:09

Mark Peters