如何获取对象的值并将其存储在整数变量中? 在字符串中我这样做:
String k = s_extend.getValue().toString();
那 int 类型怎么处理?
你可以使用 Integer.valueOf() 或者 Integer.parseInt();除非你的问题还有其他需要解决的地方 -
public static void main(String[] args) {
String str = "1";
int a = Integer.valueOf(str); // java.lang.Integer return(ed)
int b = Integer.parseInt(str); // primitive (int) return(ed)
System.out.printf("a = %d, b = %d\n", a, b);
}
在我的电脑上运行这个命令的结果是:
a = 1, b = 1
Integer.parseInt()
吗? - Baby