user2504767
user2504767

Reputation:

How to create a String Array with additional characters?

How is it possible to create a String array with some special characters like Ö, ä, Ü and so on.

That is very important for me since UTF 8 encoding. Now this solution with a String Array directly in java code causes a error:

String[] invalidCharacters = { "!", "\"", "§", "%", "&", "/", "\\", "{", "}", "[", "]",
        "(", ")", "`", "´", "'", "²", "µ", "#", "+", "~", ",", ";", ":", "_", "<", ">", ".",
        "|", "@", "^", "°", "ü", "Ü", "ä", "Ä", "ö", "Ö", "ß", "Ø", "ø", "å", "æ", "Æ" };

I get the error "unmappable character for encoding UTF8"

Is the only way to work with an external file and read the content of this file?

Upvotes: 1

Views: 103

Answers (2)

Henry
Henry

Reputation: 43728

There are two options: you can directly put the characters into the file as you did, but then the encoding of the file must match the encoding used by the compiler (see the -encoding option of the compiler).

The other way is to use unicode escapes like \u00f6 for ö.

Upvotes: 1

Maroun
Maroun

Reputation: 95948

The compiler assumes your input (Source file) is encoded with UTF-8, make sure your editor (Eclipse, Netbeans..) saves the file with UTF-8 and not any other encoding.

Upvotes: 1

Related Questions