Java數據類型中String、Integer、int相互間的轉換

          1.Integer轉換成int的方法

          Integer i = new Integer(10); 
          int k = i.intValue();
          即Integer.intValue();

           

          2.int轉換成Integer

          int i = 10;

          Integer it = new Integer(i);

           

          3.String轉換成int的方法

          String str = "10";  
          Integer it = new Interger(str);  

          int i = it.intValue();  

          即:int i = Integer.intValue(string);

           

          4.int轉換成String

          int i = 10;

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

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

          (3)String s = "" + i;

           

          5.String轉換成Integer

          String str = "10";

          Integer it = Integer.valueOf(str);

           

          6.Integer轉換成String

          Integer it = new Integer(10);

          String str = it.toString();

           

          7.String轉換成BigDecimal

          BigDecimal bd = new BigDecimal(str);

           

          8.日期

          Calendar calendar = Calendar.getInstance();
          int year = calendar.get(Calendar.YEAR);
          int month = calendar.get(Calendar.MONTH)+1;
          int day = calendar.get(Calendar.DATE);

          //獲取今天的日期字符串
          String today = java.text.DateFormat.getDateInstance().format(new java.util.Date());
          //獲取今天的日期
          new java.sql.Date(System.currentTimeMillis());

          posted on 2011-02-28 14:12 小羅 閱讀(118522) 評論(5)  編輯  收藏

          評論

          # re: Java數據類型中String、Integer、int相互間的轉換 2014-08-04 11:25 heh

          6.Integer轉換成String

          Integer it;

          String str = it.toString();

          大哥你真有才。 這么惡心代碼都能寫出來  回復  更多評論   

          # re: Java數據類型中String、Integer、int相互間的轉換[未登錄] 2015-01-28 17:34 啊啊

          @heh
          哈哈  回復  更多評論   

          # protected void onProgressUpdate(integer... values) { //int value = values[0].intValue(); progress.setProgress(); } 2015-08-17 14:21 顏靜

          protected void onProgressUpdate(integer... values) {
          //int value = values[0].intValue();
          progress.setProgress();

          }  回復  更多評論   

          # re: Java數據類型中String、Integer、int相互間的轉換[未登錄] 2015-08-20 16:59 123

          hao   回復  更多評論   

          # re: Java數據類型中String、Integer、int相互間的轉換 2016-01-12 11:10 jcc

          @jcc
          不好意思,看了下api,有這個方法,我可能是其他地方出問題了  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          <2015年1月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Web Framework

          常上的技術網站

          查找資料的java網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 进贤县| 忻州市| 柞水县| 巴塘县| 镶黄旗| 铜鼓县| 蒙城县| 花垣县| 三亚市| 垦利县| 浦城县| 金秀| 和硕县| 额敏县| 临高县| 巴彦县| 集安市| 博湖县| 五河县| 延边| 沅陵县| 元氏县| 巫山县| 门源| 即墨市| 韩城市| 镇江市| 洪江市| 东莞市| 临汾市| 清流县| 金乡县| 沙洋县| 肥城市| 石台县| 临汾市| 彝良县| 台江县| 辰溪县| 蛟河市| 阜新|