Home > Java > javaTutorial > body text

The difference between valueOf, parseInt and toString in Java

零下一度
Release: 2017-05-25 14:50:50
Original
2416 people have browsed it

1.parseInt() converts the String type into the int type.
Such as String a= "123";

int
 b = 
Integer
.parseInt(a);
Copy after login

This way b is equal to 123.

2.ValueOf() method, for example, Integer.valueOf() converts the String type into the Integer type (note: it is the Integer type, not the int type. The int type is a simple type that represents numbers, and the Integer type It is a complex type that refers to )
For example:

String a= "123";
Integer c =Integer.valueOf(a);
//Integer类型可以用int
Value方法
转化为int类型
int b =c.intValue();
Copy after login

At this time, b is equal to 123

String.valueOf(int) returns the string representation of the int parameter.

This representation happens to be the result returned by the single-parameter Integer.toString method.

3. toString() can convert a reference type into the String string type.
The following example is the opposite of 2, converting Integer into String type:

Integer a = 
new
 Integer(123);
String b =a.toString();
Copy after login

At this time, b is "123"

[Related recommendations]

1. Detailed explanation of valueOf method examples in java

2. The difference between valueOf and toString, (String) in Java

3 . Usage of tostring() and valueof() and the difference between the two

4.In-depth understanding of valueOf function and toString method

5. Introduction to object conversion functions toString() and valueOf()_

6. Use toString() method to return time as a string

The above is the detailed content of The difference between valueOf, parseInt and toString in Java. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template