Methods like ord and chr from Python

Kyle93 picture Kyle93 · Nov 27, 2013 · Viewed 17.3k times · Source

Do you know any functions that would preform the same as ord and chr from Python in Java.

Python docs on them.

I've experienced manually but seem to get so many errors. This would need to work with Strings not just char. Figured I would see if there was a function to do it pre-built.

Thanks

Answer

Simeon Visser picture Simeon Visser · Nov 27, 2013

You can cast:

c = (char) n;

n = (int) c;