社区
Java SE
帖子详情
String如何转换成int?
zhuo_chang
2004-01-12 11:00:18
谢谢了~
...全文
31
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)
String
转
int
本套视频详细讲解了
String
如何
转换成
int
,这在开发实践中会频繁遇到。
int
类型需要从文本框录入,如学生身高,服务器接收到的是
String
类型,使用时需要
转换成
int
类型。 类型转换时需要使用到包装类的方法,8种基本...
如何在 Java 中将
String
转换为
int
?
如何将
String
转换为
int
?
Java 如何将
String
转化为
Int
在 Java 中要将
String
类型转化为
int
类型时,需要使用
Int
eger 类中的 parse
Int
() 方法或者 valueOf() 方法进行转换. 例1: 1 2 3 4 5 6
String
str = "123"; try {
int
a = ...
如何将字串
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(); 注...
java中
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(); 注: 字串...
Java SE
62,614
社区成员
307,327
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章