哪一个是更快? Integer.valueOf(字符串字符串)或的Integer.parseInt(String s)返回?字符串、更快、Integer、valueOf

2023-09-05 08:52:22 作者:你是我的阳光

我想知道哪种方法更快?

I want to know which method is faster?

Integer.valueOf(字符串字符串)的Integer.parseInt(String s)返回

有两种方法之间的任何性能或内存的区别?

Is there any Performance or Memory difference between the two approaches?

我已经看到了Difference parseInt函数和的valueOf在Java?中但之间,这并不解释在性能方面的差别。

I have seen Difference between parseInt and valueOf in java? but this does not explains difference in terms of performance.

推荐答案

我不看性能。该API表示, Integer.valueOf(字符串)是PTED一样的,如果它被传递到除$ P $的Integer.parseInt(字符串) ,只不过它被包装成整数。我想看看你所需要的:一个整数 INT

I would not look at performance. The API says that Integer.valueOf(String) is interpreted the same as if it has been passed to Integer.parseInt(String), except it is wrapped into an Integer. I would look at what you need: an Integer or an int.

Integer.valueOf 返回整数

的Integer.parseInt 返回 INT