Value in properties file split by comma, reading file only loads first element

java, properties, split

Solution

It appears you're using Apache's PropertiesConfiguration. The docs states

value can contain value delimiters and will then be interpreted as a list of tokens. Default value delimiter is the comma ','.

`getString` only returns the first token. You need to use `getStringArray` to return all the properties

String recipients = config.getStringArray("email.recipients");

Problem

I have a properties file called `configuration.properties`, within `configuration.properties` is the key-value pair: ``` email.recipients = sam@yahoo.com, bob@yahoo.com ``` In my `Util.java` class I load the `configuration.properties` file: ``` import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.ConfigurationException; PropertiesConfiguration config = new PropertiesConfiguration("configuration.properties"); EMAIL_RECIPIENT_STRING = config.getString("email.recipients"); ``` I expected to have `EMAIL_RECIPIENT_STRING` = "sam@yahoo.com, bob@yahoo.com", but I get `EMAIL_RECIPIENT_STRING` = "sam@yahoo.com" only. What's the reason for this happening?

Original source