Rising Sun

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            148 隨筆 :: 0 文章 :: 22 評(píng)論 :: 0 Trackbacks
          1如何將字串 String 轉(zhuǎn)換成整數(shù) int?

          A. 有兩個(gè)方法:

          1). int i = Integer.parseInt([String]); 或
          i = Integer.parseInt([String],[int radix]);

          2). int i = Integer.valueOf(my_str).intValue();

          注: 字串轉(zhuǎn)成 Double, Float, Long 的方法大同小異.


          2 如何將整數(shù) int 轉(zhuǎn)換成字串 String ?


          A. 有叁種方法:

          1.) String s = String.valueOf(i);

          2.) String s = Integer.toString(i);

          3.) String s = "" + i;

          注: Double, Float, Long 轉(zhuǎn)成字串的方法大同小異.



          JAVA數(shù)據(jù)類(lèi)型轉(zhuǎn)換 ynniebo [收藏]
          關(guān)鍵字 類(lèi)型轉(zhuǎn)換
          出處

          這是一個(gè)例子,說(shuō)的是JAVA中數(shù)據(jù)數(shù)型的轉(zhuǎn)換.供大家學(xué)習(xí)引

          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 2006-07-18 11:07 brock 閱讀(259) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: 簡(jiǎn)要JAVA數(shù)據(jù)類(lèi)型轉(zhuǎn)換 2012-08-10 11:17 三司使
          你有對(duì)這個(gè)例子 運(yùn)行過(guò)嗎  回復(fù)  更多評(píng)論
            


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 翼城县| 南岸区| 吉首市| 舟曲县| 电白县| 平利县| 长泰县| 潮州市| 临夏市| 三门县| 灌阳县| 台江县| 梁河县| 霍城县| 三原县| 云浮市| 唐河县| 鄂伦春自治旗| 柳河县| 齐齐哈尔市| 宁明县| 南昌市| 浙江省| 漯河市| 无锡市| 耿马| 焦作市| 营口市| 威远县| 静海县| 宣恩县| 白朗县| 齐齐哈尔市| 平罗县| 鄂托克前旗| 嘉黎县| 屏东市| 阿尔山市| 宜丰县| 乐陵市| 宕昌县|