sooxin-JAVA

          JAVA中常用數據類型轉換函數

          JAVA中常用數據類型轉換函數:

           

          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 d) 

          這是一個例子,說的是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); 


           

          posted on 2007-05-08 14:53 sooxin 閱讀(363) 評論(0)  編輯  收藏 所屬分類: JAVA

          主站蜘蛛池模板: 工布江达县| 肃南| 繁峙县| 垦利县| 晋州市| 伊宁县| 阿克苏市| 郑州市| 乳源| 仪征市| 嘉鱼县| 昌宁县| 成安县| 徐州市| 苏州市| 调兵山市| 沈丘县| 泸西县| 盐源县| 八宿县| 泸定县| 衡阳市| 土默特左旗| 宾川县| 奉节县| 兴城市| 和政县| 修武县| 武邑县| 自治县| 双城市| 景谷| 南平市| 绥德县| 穆棱市| 贵溪市| 永福县| 左云县| 肇源县| 邹城市| 同仁县|