1 How do I convert string strings to integer int?
A. There are two methods:
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 converted to Double, Float, and Long in a similar way.
2 How do I convert an integer int to a string string?
A. There are three ways:
1.) String s = string.valueof (i);
2.) String s = integer.tostring (i);
3.) String s = "" + I;
Note: Double, Float, Long turn into a string in a similar way.
Java data type conversion Ynniebo [Favorites]
Keyword type conversions
Source
This is an example of the conversion of data numbers in Java. For everyone to learn
Package cn.com.lwkj.erts.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 (INTSTR);
return Integer.intvalue ();
}
change int type to the string type
public static String inttostring (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 datetostring (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);
}
}
Common data type conversion functions in Java
Although all can be found in the Java API, tidy up to 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 parseint (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 D)
Java Integer and string conversion (GO)