简要JAVA数据类型转换
1如何将字串 string 转换成整数 int? a. 有两个方法:
1). int i = integer.parseint([string]); 或 i = integer.parseint([string],[int radix]);
2). int i = integer.valueof(my_str).intvalue(); 注: 字串转成 double, float, long 的方法大同小异.
2 如何将整数 int 转换成字串 string ? a. 有叁种方法:
1.) string s = string.valueof(i);
2.) string s = integer.tostring(i);
3.) string s = "" + i; 注: double, float, long 转成字串的方法大同小异.
java数据类型转换 ynniebo [收藏]
这是个例子,说的是java中数据数型的转换.供大家学习引导
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);
}
}
java中常用数据类型转换函数 虽然都能在java api中找到,整理一下做个备份。
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 a)
1如何将字串 string 转换成整数 int? a. 有两个方法:
1). int i = integer.parseint([string]); 或 i = integer.parseint([string],[int radix]);
2). int i = integer.valueof(my_str).intvalue(); 注: 字串转成 double, float, long 的方法大同小异.
2 如何将整数 int 转换成字串 string ? a. 有叁种方法:
1.) string s = string.valueof(i);
2.) string s = integer.tostring(i);
3.) string s = "" + i; 注: double, float, long 转成字串的方法大同小异.
java数据类型转换 ynniebo [收藏]
这是个例子,说的是java中数据数型的转换.供大家学习引导
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);
}
}
java中常用数据类型转换函数 虽然都能在java api中找到,整理一下做个备份。
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 a)