3

I want to set german words (with special characters) into String var.

String s = "Staatsangehörigkeit";
System.out.println(s);

but in output or in debuger I see: Staatsangeh?rigkeit.

f_puras
  • 2,521
  • 4
  • 33
  • 38
  • 2
    Maybe your output's font doesn't contain this character? – Danil Gaponov Jul 27 '15 at 12:30
  • possible duplicate of [Display special characters using System.out.println](http://stackoverflow.com/questions/10933620/display-special-characters-using-system-out-println) – Hacketo Jul 27 '15 at 12:30
  • 1
    To get correct results you can use System.console().writer().println() instead. http://stackoverflow.com/a/4747502/3651739 – Jishnu Prathap Jul 27 '15 at 12:31
  • I have tried running the same but i am getting the correct output, maybe as mentioned above you won't be having font support for German. – Kulbhushan Singh Jul 27 '15 at 12:37
  • That can be the case, if the console is say for the Greek encoding. Then `ö` cannot be represented. – Joop Eggen Jul 27 '15 at 12:39
  • You can use Locale for this Check the link https://docs.oracle.com/javase/tutorial/i18n/locale/create.html. – Ajith John Jul 27 '15 at 13:13

2 Answers2

4

One way is to change the encoding of your project to UTF-8.

When using eclipse:

  1. Right-Click on your project folder
  2. Properties
  3. Resource
  4. Then change the text-file encoding
Lukas Rotter
  • 4,158
  • 1
  • 15
  • 35
0

The '?' is caused by "umlaute" ä = ae, ü = ue, ö = oe.

Laura
  • 19
  • 4