1.parseInt() converts the String type into the int type.
Such as String a= "123";
int b = Integer .parseInt(a);
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 thatrefers to)
For example:
String a= "123"; Integer c =Integer.valueOf(a); //Integer类型可以用int Value方法 转化为int类型 int b =c.intValue();
At this time, b is equal to 123
String.valueOf(int) returns thestringrepresentation 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();
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!
The difference between static web pages and dynamic web pages
What is the difference between 4g and 5g mobile phones?
The difference between k8s and docker
The difference between JD.com's self-operated flagship store and its official flagship store
Usage of parseInt in Java
The difference between front-end and back-end
What is the difference between php7 and php8
How to close secure boot