java - Is there a better alternative to iterate through a large list by first converting it to hash map, then finding object by its id as key -
java - Is there a better alternative to iterate through a large list by first converting it to hash map, then finding object by its id as key -
i building spring rest application nutrient store in admin can create new menu everyday adding, editing or removing menu items per occasion. when admin tries update menu, @ server side fetching first menu item list associated current menu passed , converting hash map find menu items passed menu. next code snippet convert list map:
private map<long, menuitem> convertidtomenu(list<menuitemmappingwrapper> menuitemmappingwrapper){ list<long> menuitemidlist = new arraylist<long>(); (menuitemmappingwrapper menuitemwrapper : menuitemmappingwrapper) { menuitemidlist.add(menuitemwrapper.getmenuitemid()); } list<menuitem> menuitemlist = menudao.getmenuitembyid(menuitemidlist); map<long, menuitem> menuitemmap = new hashmap<long, menuitem>(); (menuitem menuitem : menuitemlist) { menuitemmap.put(menuitem.getid(), menuitem); } homecoming menuitemmap; }
so can find menu item passing "id" key map rather iterating on big list of items. there more improve improve performance on server side other converting list map ?
java spring performance list map
Comments
Post a Comment