What is the use of public final String[] getStringArray(String key)
in ResourceBundle?
Aren't keys
in properties files unique? Would this ever return more than one value? If not why does it return an array?

- 18,826
- 34
- 135
- 254
2 Answers
If you read carefully the documentation of ResourceBundle
, its says that: -
Resource bundles belong to families whose members share a common base name, but whose names also have additional components that identify their locales.
Also: -
Resource bundles contain key/value pairs. The keys uniquely identify a locale-specific object in the bundle.
So, keys are only unique for a particular locale. In two different locale, you can have keys that are same. That is why the return type is String[]
.
And for the method - getStringArray
: -
Gets a string array for the given key from this resource bundle or one of its parents.

- 209,639
- 45
- 409
- 525
The value in a ResourceBundle
does not have to be a String
, the value can be any Object. In this case you expect it to be a String[]
.
From the javadoc you linked:
Keys:
Resource bundles contain key/value pairs. The keys uniquely identify a locale-specific object in the bundle.
Values:
Keys are always Strings. In this example, the keys are "OkKey" and "CancelKey". In the above example, the values are also Strings--"OK" and "Cancel"--but they don't have to be. The values can be any type of object.

- 2,617
- 2
- 24
- 36