Home > Net >  How to filter out a particular keyword(part/Substring) which is unique from a map key?
How to filter out a particular keyword(part/Substring) which is unique from a map key?

Time:02-02

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());
  • Related