Home  >  Article  >  Java  >  Comparison of two methods of converting Integer to int in Java

Comparison of two methods of converting Integer to int in Java

高洛峰
高洛峰Original
2017-02-11 15:48:202417browse

This article mainly introduces the comparison of two methods of converting Java Integer to int. It has a very good reference value. Let’s take a look at it with the editor.

Method 1:

Integer.parseInt(); Returns an int value.

Method 2:

new Integer.valueof();         返回的是 Integer 的对象。
new Integer.valueof().intValue();   返回的也是一个 int 的值。

Written test application examples:

Set the following two assignment statements:

a = Integer.parseInt(“123”);
b = Integer.valueOf(“123”).intValue();

The following statement is correct (d)

A. a is an integer type variable, and b is an integer type object.

B, a is an integer type object, and b is an integer type variable.

C, a and b are all integer class objects and their values ​​are equal.

D, a and b are all integer type variables and their values ​​are equal.

For more related articles comparing the two methods of converting Integer to int in Java, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn