Search code examples
javaunicodecharacterchars

How to handle unicode chars in Java


I have been trying to achieve the following :

I want to be able to paste a string of Unicode characters ex : ๐Ÿ–•๐Ÿผ๐Ÿ™…๐Ÿฝ without java showing them as being unrecognized. How do I make a Java JTextPane able to handle Unicode characters?


Solution

  • If you want to use Unicode character you have to write it like this: \u[unicode]. So for example:

     JOptionPane.showMessageDialog(null, "\u2764Guess number", "game", JOptionPane.INFORMATION_MESSAGE);
    

    would produce the folowing: โคGuess number. I hope I answered your question.