比如int转成byte数组,string转byte数组,string和基本类型之间的转换等等。

解决方案 »

  1.   

    string 和基本类型转换可以查Api拉,比如到浮点型。Double.paseDouble(String);要转数组的话只能循环一个个转啦
      

  2.   

    1.JAVA中常用数据类型转换函数
    string to byte
    Byte static byte parseByte(String s) 
    byte to string 
    Byte static String toString(byte b) 
    char to string 
    Character static String to String (char c) 
    string to Short 
    Short static Short parseShort(String s) 
    Short  to String 
    Short static String toString(Short s) 
    String to Integer 
    Integer static int parseInt(String s)
    Integer to String 
    Integer static String tostring(int i) 
    String to Long 
    Long static long parseLong(String s) 
    Long to String 
    Long static String toString(Long i) 
    String to  Float 
    Float static float parseFloat(String s) 
    Float to String 
    Float static String toString(float f) 
    String to Double 
    Double static double parseDouble(String s)
    Double to String
    Double static String toString(Double d) 
    2. 类的数据类型转换
    //转换string为int
    public static int stringToInt(String intstr)
    {
    Integer integer;
    integer = Integer.valueOf(intstr);
    return integer.intValue();
    }
    //转换int为string
    public static String intToString(int value)
    {
    Integer integer = new Integer(value);
    return integer.toString();
    }
    //转换string为float
    public static float stringToFloat(String floatstr)
    {
    Float floatee;
    floatee = Float.valueOf(floatstr);
    return floatee.floatValue();
    }
    //转换float为string
    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();
    }
      

  3.   

    通常直接使用API
        final static char[] digits = {
            '0' , '1' , '2' , '3' , '4' , '5' ,
            '6' , '7' , '8' , '9' , 'a' , 'b' ,
            'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
            'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
            'o' , 'p' , 'q' , 'r' , 's' , 't' ,
            'u' , 'v' , 'w' , 'x' , 'y' , 'z'
            };
    private static String toUnsignedString(int i, int shift) {
            char[] buf = new char[32];
            int charPos = 32;
            int radix = 1 << shift;
            int mask = radix - 1;
            do {
                buf[--charPos] = digits[i & mask];
                i >>>= shift;
            } while (i != 0);        return new String(buf, charPos, (32 - charPos));
            }
      

  4.   

    这样的函数很多啊,比如Integer.valueof()