Avoid instantiating new objects inside loops in java -
i avoid crating new instance of selectitem
in side loop. please me how can avoid it.
public list<selectitem> createlocales() { final list<selectitem> enabledlocales = new arraylist<selectitem>(); final list<string> langcodes = labeldbservice.getenabledlocales(); logger.debug("getenabledlocales: size={0}", langcodes); (final string langcode : langcodes) { enabledlocales.add(new selectitem(langcode, localeutils.tolocale(langcode).getdisplayname())); } return enabledlocales; }
public list<selectitem> createlocales() { final list<selectitem> enabledlocales = new arraylist<selectitem>(); final list<string> langcodes = labeldbservice.getenabledlocales(); final selectitem sitem = new selectitem(); logger.debug("getenabledlocales: size={0}", langcodes); (final string langcode : langcodes) { sitem.setvalue(langcode); sitem.setlabel(localeutils.tolocale(langcode).getdisplayname()); enabledlocales.add(sitem); } return enabledlocales; }
Comments
Post a Comment