Convert from Type X to Type Y

zhaozj2021-02-08  380

Integer to String:

INT i = 42;

String str = integer.toString (i);

oral

String str = "" i

Double to string:

String str = double.tostring (i);

Long to string:

String str = long.tostring (l);

FLOAT TO STRING:

String str = float.tostring (f);

String to integer:

Str = "25";

INT i = integer.valueof (str) .intValue ();

oral

INT i = integer.parseint (STR);

String to double:

Double d = double.valueof (str) .doublevalue ();

String to long:

Long L = long.valueof (str) .longvalue ();

oral

Long L = long.parselong (str);

String to float:

Float f = float.Valueof (str) .floatvalue ();

Decimal to binary:

INT i = 42;

String binstr = integer.tobinaryString (i);

Decimal to Hexadecimal:

INT i = 42;

String hexstr = INTEGER.TOSTRING (i, 16);

oral

String hexstr = INTEGER.TOHEXSTRING (i);

Hexadecimal (String) To Integer:

INT I = Integer.Valueof ("B8DA3", 16) .intValue ();

oral

INT i = integer.parseint ("B8DA3", 16);

ASCII Code to String:

INT i = 64;

String achar = new character ((char) i) .tostring ();

Integer to ASCII Code (Byte):

CHAR C = 'a';

INT i = (int) c; // i will have the value 65 decimal

TO Extract Ascii Codes from a string:

String test = "abcd";

For (int i = 0; i

CHAR C = Test.Charat (i);

INT i = (int) C;

System.out.println (i);

}

INTEger to Boolean:

B = (i! = 0);

Boolean to integer:

i = (b)? 1: 0;

Note: To Catch Illegal number converness

Try {

i = integer.parseint (astring);

}

Catch (NumberFormatexception E)

{

}

v

转载请注明原文地址:https://www.9cbs.com/read-846.html

New Post(0)