Strings are immutable, char [] is not. If you define this as a public βconstantβ in a class, then String is a real constant.
For example, if you have this:
public class MyClass { public static final char[] CODE_LETTERS = {'h', 'e', 'l', 'l', 'o'}; .... }
I can be all vile and do this:
MyClass.CODE_LETTERS[0] = 'Q';
Bam, I changed the value of your "constant".
The final keyword only affects an array reference; this does not apply to array elements. I see a similar error all the time with Collections.unmodifiableList() , people think they are protecting their list, but client code can still access and change the list items.
To answer your question, use String.
Mike kucera
source share