简要JAVA数据类型转换 (转载)

简要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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值