How do I specify values in a properties file so they can be retrieved using ResourceBundle#getStringArray?

A Properties object can hold Objects, not just Strings. That tends to be forgotten because they’re overwhelmingly used to load .properties files, and so often will only contain Strings. The documentation indicates that calling bundle.getStringArray(key) is equivalent to calling (String[]) bundle.getObject(key). That’s the problem: the value isn’t a String[], it’s a String.

I’d suggest storing it in comma-delimited format and calling split() on the value.

Leave a Comment