Java整數和字符串的相互轉化


1、把int轉化為String

以下三種方式把整形地i轉化為字符串s,當然把Double、Float、Long轉化為字符串操作一樣。

1.String s=""+i;
2.String s=Integer.toString(i);
3.String s=String.valueOf(i);

2、把String轉化為int型。

1.int i=Integer.parsenInt(s);
2.int i=Integer.valueOf(s).intValue();

3、把Integer轉化為String

Integer integer=String()

4、把String轉化為Integer

Integer integer=Integer.valueOf(i)

5、把int轉化為Integer

Integer integer=new Integer()

6、把Integer轉化為int

int num=Integer.intValue()

7、把String轉化為BigDecimal

BigDecimal bd=new BigDecimal(str)

8、把整型數x轉化為char

char a =(char)('a'+x)

————————————————
版權聲明:本文為CSDN博主「eacxzm」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/eacxzm/article/details/80064752


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM