JAVA string for char

I have a string representing the hex value of a char, for example: "0x6d4b". How can I get the character that it represents as char?

String c = "0x6d4b"; char m = ??? 
+6
source share
4 answers
 // Drop "0x" in order to parse String c = "6d4b"; // Parse hexadecimal integer int i = Integer.parseInt( c, 16 ); // Note that this method returns char[] char[] cs = Character.toChars( i ); // Prints ζ΅‹System.out.println( cs ); 
+9
source
 String s = "6d4b"; int i = Integer.parseInt( s, 16 ); // to convert hex to integer char ca= (char) i; System.out.println(ca); 
+2
source
 System.out.println((char)Integer.parseInt("6d4b",16)); 
0
source

Try it,

 String s ="0x6d4b" ; char[] c = s.toCharArray(); for (char cc : c){ System.out.print(cc); } 
-1
source

Source: https://habr.com/ru/post/919099/


All Articles