admin管理员组

文章数量:1336614

Although I do understand that javascript and Java are very different programming languages, I like the method fromCharCode () with which I can convert a unicode character like 65 to A etc. Is there a method within Java which will allow me to do the same?

Example of use fromCharCode() in javascript:

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var res = String.fromCharCode(83);
document.getElementById("demo").innerHTML=res;
}
</script>

Although I do understand that javascript and Java are very different programming languages, I like the method fromCharCode () with which I can convert a unicode character like 65 to A etc. Is there a method within Java which will allow me to do the same?

Example of use fromCharCode() in javascript:

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var res = String.fromCharCode(83);
document.getElementById("demo").innerHTML=res;
}
</script>
Share Improve this question asked Mar 5, 2014 at 1:59 user3346999user3346999 3
  • 2 Cast the integer value to a char: (char) 83 yields 'S'. – rgettman Commented Mar 5, 2014 at 2:02
  • 1 In Java Use Character.toString((char)65) which return A – ρяσѕρєя K Commented Mar 5, 2014 at 2:06
  • possible duplicate of Creating Unicode character from its number – Merlevede Commented Mar 5, 2014 at 2:06
Add a ment  | 

1 Answer 1

Reset to default 6

You can cast the integer to char

int i = 83;
char c = (char)83;

if you want to get the string:

String s = Character.toString(c);

本文标签: Is there a Java equivalent of the Javascript method fromCharCode()Stack Overflow