4

I want to initialize a String in Java with japanese characters as below.

String str = "最終条件";

But when I type in my Eclipse Java editor, it is displayed like this

String str = "|||||||";

What should be the reason and how can i solve it?

brimborium
  • 9,362
  • 9
  • 48
  • 76
Ketan
  • 2,612
  • 5
  • 31
  • 44
  • Are that really seven bars for the four Japanese characters? Then it could be more than a font problem. What happens if you enter the characters as Unicode sequences? Are they displayed correctly in other views then, e.g. the Javadoc rendering? – Hauke Ingmar Schmidt Jan 27 '12 at 22:50

3 Answers3

3

Have you tried changing the text file encoding in your project properties?

Right-click on your project, click "Properties" and change "Resource" -> "Text file encoding" to "UTF-8", "Shift_JIS" or any other suitable encoding.

moffermann
  • 31
  • 2
2

Try changing the font used by the text editor to one that supports Japanese characters. Menu: Window -> Preferences -> General -> Appearance -> Colors and Fonts -> Basic -> Text Font -> Edit

Here is a SO thread about Unicode fonts: https://stackoverflow.com/questions/586503/complete-monospaced-unicode-font

Good luck!

Community
  • 1
  • 1
Sorin
  • 1,965
  • 2
  • 12
  • 18
1

You can also rely on the \u sequences for your Japanese character. For instance, you can use a tool like http://www.snible.org/java2/uni2java.html which converts any char sequence pasted in to the text area into a Java String.

YMomb
  • 2,366
  • 1
  • 27
  • 36