Home  >  Article  >  Java  >  How to convert string to number in java

How to convert string to number in java

王林
王林Original
2020-10-20 11:09:0810898browse

Java method to convert string to number: [Integer.valueOf("12")]. If you want to convert numbers to strings, you can use the [String.valueOf(12)] method.

How to convert string to number in java

Conversion between string and int

(Recommended tutorial: java course)

Convert string to int:

Integer.valueOf("12")

Convert int to string:

String.valueOf(12)

Conversion between char and int

First convert char to string

String str=String.valueOf('2')
Integer.valueof(str)

Or

Integer.PaseInt(str)

Integer.valueof returns an Integer object, and Integer.paseInt returns an int

Related recommendations: Java Getting Started

The above is the detailed content of How to convert string to number in java. For more information, please follow other related articles on 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