Brief Java Data Type Conversion

xiaoxiao2021-03-05  18

Brief Java Data Type Conversion

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.

Java data type conversion

Keyword type conversion

Somewhere

This is an example that is said to be conversion of data digital in Java. For everyone to learn

Package cn.com.lwkj.rts.Register;

Import java.sql.date;

Public class typechange {

Public typechange () {

}

// Change the string type to the int TYPE

Public 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);

}

}

Data type conversion function in Java

Although it can be found in the Java API, make a backup.

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

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

New Post(0)