zoukankan      html  css  js  c++  java
  • 字符串与基本数据的相互转换

    (1)java.lang包中的Integer类调用其类方法public static int parseInt(String s)可以将数字格式的字符串转换为int型数据,用例如下:

    int x;  String s="123456";   x=Integer.parseInt(s);

    (2)类似的,使用java.lang包中的Byte、Short、Long、Float、Double类调用相应的类方法:

    public static byte parseByte(String s) throws NumberFormatException

    public static short parseShort(String s) throws NumberFormatException

    public static long parseLong(String s) throws NumberFormatException

    public static float parseFloat(String s) throws NumberFormatException

    public static double parseDouble(String s) throws NumberFormatException

    将数字类格式的字符串转换为相应的基本数据类型

    (3)可以使用String类的下列方法:

    public static String valueOf(byte n) 

    public static String valueOf(int n) 

    public static String valueOf(short n) 

    public static String valueOf(long n) 

    public static String valueOf(float n) 

    public static String valueOf(double n) 将数值转换为字符串,格式如下:

    String str=String.valueOf(1234.789);

    (4)可以使用Long类的下列类方法得到整型的各种进制的字符串表示。

    public static String toBinaryString(long i)

    public static String toOctalString(long i)

    public static String toHexString(long i)

    public static String toString(long i,int p)//p进制

    样例如下:

  • 相关阅读:
    新建maven web工程报错
    Linux的系统suspend和resume
    Linux内核配置---menuconfig
    printk()函数学习笔记
    驱动调试笔记
    i2c接口笔记
    无线路由器的加密模式WEP,WPA-PSK(TKIP),WPA2-PSK(AES) WPA-PSK(TKIP)+WPA2-PSK(AES)。
    Linux下sniffer实现(转)
    驱动模块(3)——Linux交叉编译工具链
    ehci ohci 驱动逻辑
  • 原文地址:https://www.cnblogs.com/zengfanye/p/9406403.html
Copyright © 2011-2022 走看看