I have a code like this
Map<String, List> searchMap = new HashMap<String, List>();
for(int i=0; i<something.size(); i++){
List<String> list = new ArrayList<String>();
list = getResult(...);
...
searchMap.put(differentkey, list);
}
Each time I am creating new List in loop. How to avoid creating new list in loop.
Simply don’t create the List at all since it is not even used in the code you have shown.