0

Given a character that is not a standard alphabet character, such as 'ⅻ', I'm having problems converting it to a string and retaining it's value. For example If I have:

String myStr = "ⅻⅾ℡ℬ";
Character myChar = myStr.charAt(0); 

Then System.out.println('ⅻ' == myChar); returns true, whereas System.out.println("ⅻ" == Character.toString(myChar)); returns false.

Thus my question effectively is how do I correctly get the value of 'ⅻ' and store it in a string?

Anya
  • 395
  • 2
  • 13

1 Answers1

1

Both of these conditions return true:

public class Test {
    public static void main(String args[]) {
        String myStr = "ⅻⅾ℡ℬ";
        Character myChar = myStr.charAt(0); 

        System.out.println('ⅻ' == myChar);
        System.out.println("ⅻ".equals(Character.toString(myChar))); 
    }
}
sleepToken
  • 1,866
  • 1
  • 14
  • 23
  • so `(Character.toString(myChar)` does actually contain "ⅻ"? – Anya Mar 04 '20 at 13:55
  • @Anya yes, `.equals()` tests for value equality. Similarly, if you called `System.out.println(Character.toString(myChar));`, the result would be `ⅻ`. – sleepToken Mar 04 '20 at 14:00