FindBugs warning: Inefficient use of keySet iterator instead of entrySet iterator

前端 未结 5 1555
别跟我提以往
别跟我提以往 2021-02-06 23:20

Please refer to the following method :

public Set getCellsInColumn(String columnIndex){
    Map cellsMap = getCell         


        
5条回答
  •  长情又很酷
    2021-02-06 23:32

    You're getting the set of keys in the map, then using each key to get the value out of the map.

    Instead, you can simply iterate through the Map.Entry key/value pairs returned to you via entrySet(). That way you avoid the relatively expensive get() lookup (note the use of the word relatively here)

    e.g.

    for (Map.Entry e : map.entrySet()) {
       // do something with...
       e.getKey();
       e.getValue();
    }
    

提交回复
热议问题