Q:

Char Array vs String: which is better for storing a set of letters

I need to store in a constant class 4 letter of a code. I can do:
static final String CODE_LETTERS = "TRWAG";

or
static final char[] CODE_LETTERS = {'T', 'R', 'W', 'A', 'G'};

After, I can obtain one of that characters in two ways:
final char codeLetter = CODE_LETTERS.charAt(index);

or
final char codeLetter = CODE_LETTERS[index];

what is the best way?. Please take in mind correction, performance, etc.

A:

Neither is incorrect, but since you're going to be dealing with the chars individually I'd personally use the char []. That said, the impact this will have on performance is going to be negligible if even measurable.

A:

Performance is irrelevant in this case.  If it's really supposed to be constant, you can't use the char[] approach.  Consider:
public class Test
{
  static final char[] CODE_LETTERS = {'T', 'R', 'W', 'A', 'G'};

  public static void main(String[] args) throws Exception
  {
    System.out.println(CODE_LETTERS[0]); // T
    CODE_LETTERS[0] = 'x';
    System.out.println(CODE_LETTERS[0]); // x
  }
}

A:

Unless you are going to fetch the character several million times in a row, you don't need to bother about the performance.

