java - 获取整数值

标签 java string integer

<分区>

如何获取对象的值并将其存储在变量 int 中?在字符串中我这样做:

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

关于java - 获取整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20557304/

相关文章:

java - 简单的 Eclipse 插件打开新文档

c++ - 不能在 C++ 中多次 append 字符串

Java - ArrayList 输出

c++ - 将 const_iterator 复制到 std::string 以保存位置

java - java中使用字符串跳出循环

java.lang.NoSuchMethodError : 'com. google.api.client.json.JsonParser

java - eclipse.ini中的 "XXMaxPermSize"和 "xmx"有什么区别?

java - ObjectInputStream.readObject() EOFException

Java:两个有序整数序列的交集

haskell - Haskell 中的除法,还是没明白