Dedian |
|
|||
-- 關(guān)注搜索引擎的開發(fā) |
日歷
統(tǒng)計(jì)
導(dǎo)航常用鏈接留言簿(8)隨筆分類(45)
隨筆檔案(82)
文章檔案(2)Java Spaces搜索積分與排名
最新評(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") ?
|
![]() |
|
Copyright © Dedian | Powered by: 博客園 模板提供:滬江博客 |