I have a list of Map of Strings like this
List<Map<String, String>> dataListMap = new ArrayList<>();
Map<String, String> dataMap = new HashMap<String, String>() {
{
put("Charged fare", "3");
put("Trip ID", "1");
put("Account", "220");
}
};
dataListMap.add(dataMap);
dataMap = new HashMap<String, String>() {
{
put("Charged fare", "5");
put("Trip ID", "2");
put("Account", "220");
}
};
dataListMap.add(dataMap);
dataMap = new HashMap<String, String>() {
{
put("Charged fare", "7");
put("Trip ID", "3");
put("Account", "230");
}
};
dataListMap.add(dataMap);
dataMap = new HashMap<String, String>() {
{
put("Charged fare", "8");
put("Trip ID", "4");
put("Account", "230");
}
};
dataListMap.add(dataMap);
I want to separate this list by the account number and convert this to two list in side a List<List<Map<String,String>>> Is there an easy way to do that?Please help
I believe that this is what you asked for but you should try specifying your use case, it can probably be better designed.
Yes you can do it with flatmap, but you already have the list at the start why would you do that?
Stream never affects the result of your initial Collection, it always returns new result, so it is safe to reuse the list you had at the start.