Data type conversion function in Java

xiaoxiao2021-03-06  15

Data type conversion function in Java

1 How to convert a string string into an integer int?

A. There are two ways:

1). INT i = integer.parseint ([string]); or

I = integer.parseint ([String], [INT RADIX]);

2). INT i = integer.valueof (my_str) .intValue ();

Note: The string is transformed into Double, Float, and long.

2 How to convert integer int converted into a string string?

A. Have a variety of methods:

String s = String.Valueof (i);

2.) String s = integer.tostring (i);

3.) String s = "" i;

Note: Double, Float, long-converted to string is similar.

1 How to convert a string string into an integer int?

A. There are two ways:

1). INT i = integer.parseint ([string]); or

I = integer.parseint ([String], [INT RADIX]);

2). INT i = integer.valueof (my_str) .intValue ();

Note: The string is transformed into Double, Float, and long.

2 How to convert integer int converted into a string string?

A. Have a variety of methods:

String s = String.Valueof (i);

2.) String s = integer.tostring (i);

3.) String s = "" i;

Note: Double, Float, long-converted to string is similar.

String-> Byte

Byte Static Byte ParsebyTe (String S)

BYTE-> STRING

Byte Static String Tostring (byte b)

Char-> string

Character Static String to String (Char C)

String-> short

Short Static Short Parseshort (String S)

Short-> string

Short Static String Tostring (SHORT S)

String-> Integer

Integer Static Int PaSeint (String S)

Integer-> String

Integer Static String Tostring (INT I)

String-> long

Long Static Long Parselong (String S)

Long-> String

Long Static String Tostring (long i)

String-> float

Float Static Float Parsefloat (String S)

FLOAT-> String

Float Static String Tostring (Float F)

String-> DOUBLE

Double Static Double Parsedouble (String S)

Double-> String

Double Static String Tostring (double)

This is an example that is said to be a conversion of data in Java.

Package cn.com.lwkj.rts.Register;

Import java.sql.date;

Public class typechange {

Public typechange () {

}

// change the string type to the int typepublic static int stringtoint (String INTSTR)

{

Integer integer;

Integer = integer.valueof (INTST);

Return Integer.intValue ();

}

// Change int Type to the String Type

Public Static String INTSTOSTOSTOSTRING (INT Value)

{

Integer Integer = New Integer (Value);

Return integer.toString ();

}

// Change the string type to the float type

Public static float stringtofloat (String floatstr)

{

Float floatee;

FLOATEE = float.valueof (floatstr);

Return floatee.floatvalue ();

}

// Change the float type to the string type

Public Static String floattostring (Float Value)

{

Float floatee = new float (value);

Return floatee.tostring ();

}

// Change the string type to the sqldate type

Public static java.sql.date stringtodate (String DateStr)

{

Return java.sql.date.valueof (dateStr);

}

// change the sqldate type to the string type

Public Static String DateTString (java.sql.date datee)

{

Return Datee.toString ();

}

Public static void main (string [] args)

{

Java.sql.date day;

Day = TypeChange.StringTodate ("2003-11-3");

String strday = typechange.datetostring (day);

System.out.println (strDay);

}

}

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

New Post(0)