Question: I have `config.properties` file that contains names.

Say it looks as such:

```
#Client1 properties
1Client=Client1
1someproperty=someproperty
#Client2 properties
2Client=Client1
2someproperty=someproperty

```

What I am trying to achieve is only getting the client names in a `DefaultListModel` so I can add them to a list. I have tried the following:

```
public static DefaultListModel SetVM() {
    int clientCode = 1;
    DefaultListModel vm_list = new DefaultListModel();
    Properties props = new Properties();
    FileInputStream fis = null;
    try {
        props.load(fis);
        fis = new FileInputStream("config.properties");
        //if (statement to see if props contains clientCode) {
            String vmClient = props.getProperty(DatabaseCode + "CLIENT");
            vm_list.addElement(vmClient);
        //}
    } catch (Exception e) {
    }
    return vm_list;
}

```

I was thinking along the line of `for(Object obj : fis)`, but that is not possible. The other option was using an iterator as discribed [here](http://www.java2s.com/Tutorial/Java/0140__Collections/UsingEnumerationtoloopthroughProperties.htm).
Though I cannot grasp how to get a certain property.

Answer: 
Try this. Using Properties entrySet which gives you the key and value for each property.

```
@Test
public void testClient () throws IOException {

    DefaultListModel<String> vm_list = new DefaultListModel<String>();
    Properties props = new Properties();
    FileInputStream fis = null;
    fis = new FileInputStream("config.properties");
    props.load(fis);
    for (Entry<Object, Object> entry : props.entrySet()) {
        System.out.println("Entry key:" + entry.getKey() + " value:" + entry.getValue());
        String key = (String)entry.getKey();
        if (key.endsWith("Client")) {
            vm_list.addElement(key); // maybe want to add entry.getValue() instead
        }
    }
    // return vm_list;      
}

```
Try something like this. Just used the regex to identify the client property.
Hope this helps.

```
Properties properties = new Properties();

    try
    {
        properties.load(new FileInputStream("config.properties"));
        for(String key : properties.stringPropertyNames()){
            if(key.matches("(\\d+)Client")){
                //add to arrayList
            }
        }
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

```