Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing UTF-8 in java

Tags:

java

utf-8

I'm attempting to print a deck of cards to system.out, with the suits represented by ♥, ♦, ♣, and ♠. I've copy-pasted the characters into my code:

deck.offer(new Card(v, (i == 0) ? "\u2666" : (i == 1) ? "♦" : (i == 2) ? "♣" : "♠"));

As you can see, I've tried escaping the symbols and directly pasting them into my code. Eclipse (the IDE that I use) gave me the option to change the encoding of the .java file to UTF-8, but my System.out.print()'s still show '?' as the symbols.

How do I print ♥, ♦, ♣, and ♠ to the terminal?

EDIT: Oleski answered my question below. Thank you!

like image 366
James Avatar asked Feb 16 '26 07:02

James


1 Answers

It's possible that the terminal you're viewing the characters in is not interpreting them as UTF-8. That is, the characters are encoded in UTF-8 correctly, but the terminal is not set to interpret them as UTF-8

like image 75
Oleksi Avatar answered Feb 18 '26 19:02

Oleksi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!