string.letters:
The concatenation of the strings lowercase and uppercase described
below. The specific value is
locale-dependent, and will be updated
when locale.setlocale() is called.
I modified the answer from Michael Borgwardt. In my implementation there are two lists lowerCases and upperCases for two reasons:
string.letters is lowercases followed by uppercases.
Java Character.isLetter(char) is more than just uppercases and lowercases, so use of Character.isLetter(char) will return to much results under some charsets, for example "windows-1252"
From Api-Doc: Character.isLetter(char):
A character is considered to be a
letter if its general category type,
provided by Character.getType(ch), is
any of the following:
* UPPERCASE_LETTER
* LOWERCASE_LETTER
* TITLECASE_LETTER
* MODIFIER_LETTER
* OTHER_LETTER
Not all letters have case. Many
characters are letters but are neither
uppercase nor lowercase nor titlecase.
So if string.letters should only return lowercases and uppercases, the TITLECASE_LETTER,
,MODIFIER_LETTER and OTHER_LETTER chars have to be ignored.
public static String allLetters(final Charset charset) {
final CharsetEncoder encoder = charset.newEncoder();
final StringBuilder lowerCases = new StringBuilder();
final StringBuilder upperCases = new StringBuilder();
for (char c = 0; c < Character.MAX_VALUE; c++) {
if (encoder.canEncode(c)) {
if (Character.isUpperCase(c)) {
upperCases.append(c);
} else if (Character.isLowerCase(c)) {
lowerCases.append(c);
}
}
}
return lowerCases.append(upperCases).toString();
}
Additionally:
the behaviour of string.letters changes when changing the locale. This maybe won't apply to my solution, because changing the default locale does not change the default charset. From apiDoc:
The default charset is determined
during virtual-machine startup and
typically depends upon the locale and
charset of the underlying operating
system.
I guess, the default charset cannot be changed within the started JVM. So the "change locale" behaviour of string.letters can not be realizied with just Locale.setDefault(Locale). But changing the default locale is anyway a bad idea:
Since changing the default locale may
affect many different areas of
functionality, this method should only
be used if the caller is prepared to
reinitialize locale-sensitive code
running within the same Java Virtual
Machine.