1

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?

5
  • 4
    What error do you get? Commented Nov 26, 2013 at 9:46
  • 2
    This will need some more context and/or explanation because it is really vague... Commented Nov 26, 2013 at 9:47
  • 3
    You can always use Unicode notation: String[] unicodeCharacters = { "\u00ea" , "\u00f1" , "\u00fc" }. Not that this solves any issue, just to let you know. Commented Nov 26, 2013 at 9:48
  • Are you sure your IDE is properly treating your code as UTF-8? Commented Nov 26, 2013 at 9:50
  • So far, you have posted 42 questions, most of this have 1 or more answers. You are free to accept none, if you want. But I think you should accept some of them and finally get the scholar badge :) Commented Dec 2, 2013 at 22:56

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@Henry How is that opposing what I said?
@MarounMaroun you said the compiler assumes UTF-8, the platform encoding may or may not be UTF-8
@Henry I was referring his case :)
1

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 ö.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.