I have an Arraylist
which has a Map
in it. I want to convert the list with respect to a key and value pair and store it into an another List.
I have a list which gives output as:
List<Map<String, String>> mainList = new ArrayList<Map<String, String>>();
{Date=29/01/2018, Type=UNI, Number=17131176}
{Date=29/01/2019, Type=UPS, Number=17592158}
{Date=29/01/2020, Type=CP2, Number=17601558}
{Date=27/01/2015, Type=CP3, Number=17457472}
{Date=27/01/2015, Type=MBY, Number=17112367}
{Date=21/01/2015, Type=CP4, Number=17843672}
How can I make this list to be used in these two methods?
public void excludeNumbers(List<String> Numbers, Date Date)
public void excludeTypes(List<String> Types, Date Date)
Try this.
excludeNumbers(mainList.stream()
.map(m -> m.get("Number"))
.collect(Collectors.toList()), date);
excludeTypes( mainList.stream()
.map(m -> m.get("Type"))
.collect(Collectors.toList()), date);