> For the complete documentation index, see [llms.txt](https://maxwell.gitbook.io/way-to-architect/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maxwell.gitbook.io/way-to-architect/java-yu-yan/mian-xiang-dui-xiang/integer.parseint-yu-interger.valueof.md).

# Integer.parseInt()与Interger.valueof()

下面的代码有什么区别：

```
Integer.parseInt("12");
Integer.valueOf("12");
```

看源码：

```
public static int parseInt(String s) throws NumberFormatException {
        return parseInt(s,10);
}
public static Integer valueOf(String s) throws NumberFormatException {
        return Integer.valueOf(parseInt(s, 10));
}
```

可以看出两者的区别：

返回值不同，parseInt(String s)返回的是int，而valueOf(String s)返回的是Integer

所以，一般用`Integer.parseInt(str)`，除非你要返回`Integer`类型，不然还有封装拆箱，性能多少会耗费些。
