Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert numbers into strings in java
How to convert numbers into strings in java
The toString () method is converted to a string.

Integer and string conversion in JAVA

1. Converts a string to an integer int.

1).int I = integer . parse int([String]); or

i = Integer.parseInt([String],[int radix]);

2).int i = Integer.valueOf(my_str)。 int value();

Note: the method of converting strings into double, float and long is similar.

2. Convert the integer int into a String?

1.)String s = String . value of(I);

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

3.) String s = ""+i;

Note: Double, float and long are converted to strings in a similar way.

JAVA data type conversion ynniebo: This is an example of data type conversion in Java. For your reference.

Package cn.com.lwkj.erts.register;

Import java.sql.date;

Public class type change {

public TypeChange() {

}

//Change the string type to int type

Public static int String point(String intstr)

{

Integer;;

integer = integer . value of(intstr);

Returns integer. intvalue ();

}

//change int type to string type.

Public static string intToString(int value)

{

Integer integer = new integer (value);

Returns integer. tostring ();

}

//Change the string type to floating-point type

Common static floating-point stringToFloat(String floatstr)

{

Float float;

float ee = float . value of(float str);

Returns floatee. floatvalue ();

}

//Change floating-point type to string type

Public static string floatToString (floating point value)

{

FloatFloat = new float (value);

Returns floatee.tostring ();

}

//Change the string type to sqlDate type.

Public static java.sql.datestringtote (string datestr)

{

Returns java.sql.date.valueof (datestr);

}

//change sqlDate type to string type.

Public static string datetostring (java.sql.datedatee)

{

return datee . tostring();

}

Public static void main(String[] args)

{

Java.sql.Date day;

day = type change . string tote(" 2003- 1 1-3 ");

Stringstrday = typechange.datetostring (day);

system . out . println(strday);

}

}

Common data type conversion functions in JAVA

String-> byte

Byte static byte analysis byte (string s)

Bytes-> line

Byte static string to string (byte b)

char-& gt; line

Character static string to string (char c)

String-> short

Short static short parseShort (string s)

Short->; line

Short static string toString (short s)

String-> integer

Integer static int parseInt (string s)

Integer-> line

Integer static string tostring(int i)

String-> long

Long static long parseLong (string s)

long->; line

Long static string toString(Long i)

String-> float

Floating-point static floating-point parseFloat (string s)

Floating-> line

Converts a static string to a string (floating point f)

String-> double;twofold

Double static double parseDouble (string s)

double-& gt; line

Double static string toString (double d)