You are retrieving all the keys (accessing the whole map) and then for some keys, you access the map again to get the value.
You can iterate over the map to get map entries (Map.Entry) (couples of keys and values) and access the map only once.
Map.entrySet() delivers a set of Map.Entry
s each one with the key and corresponding value.
for ( Map.Entry< String, LIMSGridCell > entry : cellsMap.entrySet() ) {
if ( entry.getKey().startsWith( columnIndex ) ) {
cells.add( entry.getValue() );
}
}
Note: I doubt that this will be much of an improvement since if you use map entries you will instantiate an object for each entry. I don't know if this is really faster than calling get()
and retrieving the needed reference directly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…