Concise Java Data type conversions
Last Update:2017-02-28
Source: Internet
Author: User
Data | data type | Conversion 1 How do I convert string string 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: string to Double, Float, Long is a very similar method.
2 How do I convert an integer int to string string?
A. There are three methods:
1.) String s = string.valueof (i);
2.) String s = integer.tostring (i);
3.) String s = "" + I;
Note: Double, Float, Long into a string of methods are very similar.
Java data type conversion Ynniebo [Favorites]
keyword type conversion
Source
This is an example of the conversion of data numbers in Java. For everyone to learn to lead
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
can be found in the Java API, organize 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