I created a for each loop and I get list of price code but I want to get same things without using any loop and perform this operation using java8 for your reference I post my old code. I want to change only this position of my code.
List<ItemPriceCode> itemPriceCodes = item.getItemPriceCodes(); List<String> priceCodeList = new ArrayList<String>(); for (ItemPriceCode ipc : itemPriceCodes) { //get the string value from the list priceCodeList.add(ipc.getPriceCode()); } But I do not want to use any loop I want to get same result without using any loop . To over come from this issue I try this way but I am not get any success.
itemPriceCodes.stream().map(n -> String.valueOf(n)).collect(Collectors.toList()); Here This is my full code of this function
private Item getItemManufacturerPriceCodes(Item item) { List<ItemPriceCode> itemPriceCodes = item.getItemPriceCodes(); List<String> priceCodeList = new ArrayList<String>(); for (ItemPriceCode ipc : itemPriceCodes) { //get the string value from the list priceCodeList.add(ipc.getPriceCode()); } //pass this string value in query List<ManufacturerPriceCodes>mpc = manufacturerPriceCodesRepository. findByManufacturerIDAndPriceCodeInAndRecordDeleted(item.getManufacturerID(),priceCodeList,NOT_DELETED); //Convert list to map Map<String, ManufacturerPriceCodes> ipcToMFPNameMap = mpc.stream().collect( Collectors.toMap(ManufacturerPriceCodes :: getPriceCode,Function.identity()));// Object for (ItemPriceCode ipcs : itemPriceCodes) { ipcs.setManufacturerPriceCode(ipcToMFPNameMap.getClass().getName()); } item.getItemPriceCodes() .removeIf(ipcs -> DELETED.equals(ipcs.getRecordDeleted())); return item; }