简体   繁体   中英

How to read key from value of resource bundle/properties file

I have messages.properties bundle file which contains labels in key, value pair like

meta.enum.ShipmentStatus.Loaded=Loaded

But I want read key from value ie from user/client view I get "Loaded" value and I want read key of that value ie "meta.enum.ShipmentStatus.Loaded".

How to achieve this?

You can read keys by loading all keys and values into a map. If so,

public <K, V> Stream<K> keys(Map<K, V> map, V value) {
return map
  .entrySet()
  .stream()
  .filter(entry -> value.equals(entry.getValue()))
  .map(Map.Entry::getKey); }

can return the keys for the value. But, if you are using Spring look at: https://stackoverflow.com/a/34655571/11813364

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM