Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading