I have a Map<String,String>
{
BusDetails0.BusDetail.DriverID=1,
BusDetails0.BusDetail.DriverSubID=2,
BusDetails1.BusDetail.DriverID=1,
BusDetails1.BusDetail.DriverSubID=2
}
from this map is it possible to extract keys in a list of Strings {"BusDetails0","BusDetails1"}?
please help thanks
CodePudding user response:
You can get a set of keys:
map.keySet()
In your case, if I understand correctly, you want to get a list of transformed keys (all characters before the first dot symbol)
List<String> list = map.keySet().stream().map(s -> s.split("\\.")[0]).collect(Collectors.toList());