JAVA中int怎么转换String类型?

来源:百度知道 编辑:UC知道 时间:2024/07/07 06:01:40
String id = (String)myCourseList.getSelectedValue();
以上ID是String类型的,我想把转换成Int类型的,请问怎么转换?
String id = (String)myCourseList.getSelectedValue(); 改成:int id =myClassAList.getSelectedValue().toString;
这样就没问题了,谢谢各位

Integer.parseInt((String)myCourseList.getSelectedValue());
先转String
或者 这样也可以
((Integer)myCourseList.getSelectedValue()).intValue();

说明你的值有问题!!
System.out.print((String)myCourseList.getSelectedValue());
你打印出来看看 有可能是空 "" 或者不是数字
String demo =(String)myCourseList.getSelectedValue();
demo = demo.equst("")?"0":demo;
//如果是空替换为0就可以了

Integer.ParseInt()

你加什么双引号啊,去掉