社区
Java SE
帖子详情
String如何转换成int?
zhuo_chang
2004-01-12 11:00:18
谢谢了~
...全文
96
16
打赏
收藏
String如何转换成int?
谢谢了~
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
真不知道是谁
2004-01-12
打赏
举报
回复
将字符串s转换成整型i
String s="123";
try {
i = Integer.parseInt(s);
} catch (NumberFormatException e) { //如果String包含不是整型的字符串,将抛出异常!
e.printTraceStack();
}
Leemaasn
2004-01-12
打赏
举报
回复
这种方式最保险:
try
{
int i = Integer.parseInt(s) ;
}
catch(Exception e)
{
System.out.println("No Number Format") ;
}
metome
2004-01-12
打赏
举报
回复
建议你多看API
haode
2004-01-12
打赏
举报
回复
注意要进行异常处理
tiger_wkh52741
2004-01-12
打赏
举报
回复
try
{
int i = Integer.parseInt(s) ;
}
catch(Exception e)
{
System.out.println("No Number Format") ;
}
最好.try一下.
wangsheng1028
2004-01-12
打赏
举报
回复
i = (Integer.valueOf(string)).intValue();
caiyi0903
2004-01-12
打赏
举报
回复
try
{
int i = Integer.parseInt(s) ;
}
catch(Exception e)
{
System.out.println("No Number Format") ;
}
kenli
2004-01-12
打赏
举报
回复
同上
lukelan
2004-01-12
打赏
举报
回复
最好加上异常处理
try {
i = Integer.parseInt(string);
} catch (NumberFormatException e) {
e.printTraceStack();
}
马行空牛耕田
2004-01-12
打赏
举报
回复
请使用如下代码,以保证健壮性:
String s = "123";
int i = -1 ;
try{
i = Integer.parseInt(s);
}
catch(NumberFormartException numex){
//如果转换失败,那么你的处理如下
}
hfree
2004-01-12
打赏
举报
回复
try
{
int i = Integer.parseInt(s) ; //S如果不能转化成字符,则parseint会抛出异常
}
catch(Exception e)
{
System.out.println("No Number Format") ;
}
furies21
2004-01-12
打赏
举报
回复
Integer.parseInt(String s)
giardino
2004-01-12
打赏
举报
回复
Integer.parseInt(string);
前提是你的string是能够转换成int的
ddbean
2004-01-12
打赏
举报
回复
要转化String s
int i = Integer.parseInt(s);
fft123
2004-01-12
打赏
举报
回复
String s = "1234";
int i = Integer.parseInt(s);
yangFrame
2004-01-12
打赏
举报
回复
int i=Integer.parseInt(String s)
C++
int
转换成
string
的方法
int
转
string
也是经常用到的,今天碰到了整理下,写了一个简单的宏。 #include <sstream> #define
INT
_TO_
STRING
(name,value)\
int
_i##name = value;\
string
stream ss##name;\ ss##name<<_i##name;\
string
name = ss##name.s...
java如何把
int
转换成
string
_如何将
int
转换成
String
转自:http://hi.baidu.com/shadouyou/blog/item/ccbe8d2f1258273b1e308971.html/cmtid/bf2625d12ae630379a5027fd如何将
int
转换成
String
在java中2007年09月10日 星期一 下午 05:06方法1
int
i=10;
String
s=""+i;这是利用java的to
String
机制来做的转...
Android中
string
转换成
int
int
->
String
int
i=12345;
String
s=”“; 第一种方法:s=i+”“; 第二种方法:s=
String
.valueOf(i); 这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢? 第一种方法:s=i+”“; //会产生两个
String
对象 第二种方法:s=
String
.valueOf(i); //直接使用
String
类的静态方...
如何将
int
转换成
String
转自: http://hi.baidu.com/shadouyou/blog/item/ccbe8d2f1258273b1e308971.html/cmtid/bf2625d12ae630379a5027fd 如何将
int
转换成
String
在java中 2007年09月10日 星期一 下午 05:06 方法1
int
i=10;
String
s=""+i; 这是利用ja
int
赋值给
string
java_关于java的
string
转换成
int
类型,我的注解对吗?
展开全部是的32313133353236313431303231363533e4b893e5b19e31333337623465,基本解释都是对的
String
转换成
int
比较常用的3个方法
int
x=new
Int
eger("1");//方法1
int
y=
Int
eger.valueOf("2");//方法2
int
z=
Int
eger.parse
Int
("3");//方法3System...
Java SE
62,622
社区成员
307,255
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章