how to convert char to int in java for android
for example:
int MyInt;
char MyChar = 'A';
how to insert the value 65 into MyInt ?
in C# it like:开发者_C百科 MyInt = Convert.ToChar(MyChar);
thanks
You can do it the same way in both C# and Java:
char myChar = 'A';
int myInt = myChar;
I wouldn't use Convert.ToInt32
(which is what I assume you meant) in C#... I'd just use the implicit conversion shown above.
EDIT: In Java, this uses the implicit widening primitive conversion specified in section 5.1.2 of the Java Language Specification:
The following 19 specific conversions on primitive types are called the widening primitive conversions:
- byte to short, int, long, float, or double
- short to int, long, float, or double
- char to int, long, float, or double
- [...]
精彩评论