object可以直接转int嘛

袏佑掱嘚疼 1个月前 已收到1个回答 举报

婲隻埖 3星

共回答了313个问题采纳率:91.8% 评论

object类型转换为int类型:

1.如果object是byte,short,int,char类型生成的,那么不用转换直接赋值即可。

2.如果object是字符串类型生成的,先把object转换为String类型的,再把String类型转换为int类型。

例如.String myInt="123";

Object os=myInt;

int b=Integer.parseInt((String)os);//还可以os.toString()

3.如果object是float,double,long类型生成的,思路和上面一样,先把object转换为相应的数据类型,然后再转换为int类型。

9小时前

24
可能相似的问题

热门问题推荐

Copyright © 2024 微短问答 All rights reserved. 粤ICP备2021119249号 站务邮箱 service@wdace.com