Dedian  
          -- 關(guān)注搜索引擎的開發(fā)
          日歷
          <2006年4月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456
          統(tǒng)計(jì)
          • 隨筆 - 82
          • 文章 - 2
          • 評(píng)論 - 228
          • 引用 - 0

          導(dǎo)航

          常用鏈接

          留言簿(8)

          隨筆分類(45)

          隨筆檔案(82)

          文章檔案(2)

          Java Spaces

          搜索

          •  

          積分與排名

          • 積分 - 65572
          • 排名 - 817

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

           
          It is common problem of convertion between int & string for certian computer language. Well, in Java, following are some easy ways I usually apply:

          1. int --> String
          ??? a. apply "+" operation with an empty string
          ??? ?? ?? ex:
          ??? ?? ?? int index = 20;
          ??? ?? ?? String indexStr = "" + index;
          ??? b. use String function
          ??? ?? ?? ex:
          ??? ?? ?? int index = 20;
          ??? ?? ?? String indexStr = String.valueOf(index);
          ??? c. convert to Integer class firstly
          ??? ?? ?? ex:
          ??? ?? ?? int index = 20;
          ??? ?? ?? Integer Index = new Integer(index);
          ??? ?? ?? String indexStr = Index.toString();
          ??? ?? ?? or
          ??? ?? ?? String indexStr = Integer.toString(index);

          2. String --> int
          ??? a. use class Integer parse funtion
          ??? ?? ex:
          ??? ?? String indexStr = "20";
          ??? ?? int index = Integer.parseInt(indexStr);
          ??? ?? or
          ??? ?? int index = (new Integer(indexStr)).intValue();

          note: above convertion methods can be applied to other number types, such as float, long, double...

          P.S. for 1.a method, should be noticed that following two expression are different:
          int i = 7;
          int j = 8;

          String str1 = i + j + ""; //(str1 == "15")
          String str2 = "" + i + j; //(str2 == "78")
          ?
          posted on 2006-04-25 09:22 Dedian 閱讀(736) 評(píng)論(0)  編輯  收藏 所屬分類: Java Memo
           
          Copyright © Dedian Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 醴陵市| 新巴尔虎左旗| 任丘市| 涟源市| 蓬安县| 玉门市| 陈巴尔虎旗| 六安市| 辽宁省| 山阴县| 青海省| 津南区| 田林县| 自治县| 绍兴县| 河北区| 平度市| 五家渠市| 体育| 嘉禾县| 榆中县| 兴城市| 襄城县| 同仁县| 台中县| 新昌县| 松溪县| 隆回县| 会东县| 遵化市| 二连浩特市| 嘉善县| 长垣县| 宜章县| 河曲县| 宁城县| 双江| 宜川县| 眉山市| 乐安县| 砀山县|