数字与字符串之间的转换

来源:互联网 发布:淘宝天天特价衣服 编辑:程序博客网 时间:2024/05/18 15:55

数字类型转换成字符串类型

  • > String s=String.valueOf(value) //value为任意一种数字类型

字符串类型转换成各种数字类型

  • String s=”123”;
    byte b=Byte.parseByte(s);
    short t =Short.parseShort(s);
    int i=Integer.parseInt(s)
    long l =Long.parseLong(s);
    Float f = Float.parseFloat(s);
    Double d =Double.parseDouble(s);

包装器

  •     int i=5;    //自动装箱    Integer in=5;    //使用包装器的valueOf方法    Integer ger=Integer.valueOf(i);      //自动拆箱    int t=new Integer(5);    //使用包装器的xxxvalue方法    int nt=ger.intValue();    byte b=6;           Byte by=6;    Byte byt=Byte.valueOf(b);           byte yt=byt.byteValue();    byte ye=new Byte(by);    short s=8;    Short sh=8;    Short shr=Short.valueOf(s);    short tr=shr.shortValue();    short rt=new Short(sh);     char c='c';    Character ch='c';    Character cha=Character.valueOf(c);    char ac=new Character(ch);    char ar=ch.charValue();

原创粉丝点击