Collect value of the properties without knowing the key

0

I need to know how to collect from a properties for the value of the properties. In other words, I have the following in a properties.

usuario.UE0153 = PEpe ccx dkgkdflñfg
usuario.UE1222 = Antonio perez jimenez
usuario.UE1525 = Jaime Perez 

I have to collect all the users (user.xxx) that appear in the properties without knowing what they are. That is to say not knowing it I have to go through the properties and collect each user key. then collect their values. But I do not know how to collect the keys. Then go through the value with the keys.

Greetings and thanks in advance.

    
asked by kiristof 05.03.2018 в 18:58
source

1 answer

1

Use keySet() , return a Set<Object> with all the properties entries:

Properties props = new Properties();
props.setProperty("usuario.UE0153", "a");
props.setProperty("usuario.UE1222", "b");
props.setProperty("usuario.UE1525", "c");

for(Object key : props.keySet()) {
    System.out.printf("%s : %s%n", key, props.getProperty(key.toString()));
}
//salida:
//usuario.UE1525 : c
//usuario.UE1222 : b
//usuario.UE0153 : a
    
answered by 05.03.2018 в 19:36