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 閱讀(362) 評論(0)  編輯  收藏 所屬分類: JAVA

          主站蜘蛛池模板: 垫江县| 吉首市| 太康县| 前郭尔| 同江市| 潞城市| 织金县| 米脂县| 山阴县| 吐鲁番市| 溧阳市| 永仁县| 互助| 铜山县| 石泉县| 和政县| 阿尔山市| 进贤县| 建始县| 谢通门县| 兴城市| 民权县| 武城县| 颍上县| 淮北市| 泊头市| 抚松县| 宣威市| 阆中市| 湖州市| 临夏市| 温州市| 聂拉木县| 民权县| 格尔木市| 五原县| 泰安市| 台中市| 桦南县| 利辛县| 建湖县|