Eclipse debugging HashMap: Logical Structure using Key and Value's toString() method

前端 未结 4 1496
青春惊慌失措
青春惊慌失措 2021-01-30 18:29

I have recently started to use Eclipse after using IntelliJ for a few years. When debugging Map using IntelliJ, if the key or object implements toString(), a nice list of strin

4条回答
  •  悲&欢浪女
    2021-01-30 18:49

    Well I made an ugly workaround. Set up this detail formatter for Map:

    StringBuilder detail = new StringBuilder();
    int i = 0;
    for (Object k : keySet()) {
        detail.append((i++) + ": " + k + "\n");
    }
    return detail;
    

    Then in the output of that, find the index of the entry with the key you want, then find that entry in the logical structure tree.

    It works, but the detail formatter itself is a bit slow, and it requires an extra step. Also the keys are not sorted so finding the key you want in a large map may be difficult (though sorting could theoretically be done in the formatter).

提交回复
热议问题