社区
Java SE
帖子详情
String如何转换成int?
zhuo_chang
2004-01-12 11:00:18
谢谢了~
...全文
46
16
打赏
收藏
String如何转换成int?
谢谢了~
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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)
如何在 Java 中将
String
转换为
int
?
如何将
String
转换为
int
?
如何将字串
String
转换成
整数
int
1如何将字串
String
转换成
整数
int
? A. 有两个方法: 1).
int
i =
Int
eger.parse
Int
([
String
]); 或 i =
Int
eger.parse
Int
([
String
],[
int
radix]); 2).
int
i =
Int
eger.valueOf(my_str).
int
Value(); 注...
Android
String
与
int
相互转换
目录一、如何将字串
String
转换成
整数
int
?二、 如何将整数
int
转换成
字串
String
? 一、如何将字串
String
转换成
整数
int
? 方法一:
int
i =
Int
eger.parse
Int
([
String
]);或 i =
Int
eger.parse
Int
([
String
],[
int
...
如何在 Java 中将
String
转换为
int
?
如题,如何在 Java 中将如下
String
类型的数字转换为
int
类型? "12345" → 12345 方法 使用
Int
eger.parse
Int
() 方法来实现:
String
my
String
= "12345";
int
number =
Int
eger.parse
Int
(my
String
); 需要注意的是,...
如何将字串
String
转换成
整数
int
?
int
i =
Int
eger.parse
Int
([
String
]); 或 i =
Int
eger.parse
Int
([
String
],[
int
radix]); 2).
int
i =
Int
eger.valueOf(my_str).
int
Value(); 注: 字串转成 Double, Float, Long 的方法大同小异. 2 如何
Java SE
62,634
社区成员
307,266
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章