Learn Java – How to Convert String to Int?

It is often necessary to handle data in our programs, and it is not in the format that we want. With Java, you can do conversions of objects, such as a string to int, and vice-versa. In this article, we will show you several conversions methods in Java.

Converting String to integer

Make the conversion of a String to an integer using the parseInt() method of Integer class, or by using the methods valueOf() and intValue() of the Integer class combined, as shown in the following code.


 

Converting a String to a float

Convert a String to float through the combination of the methods valueOf () and floatValue () of Float class.


 

Converting a String to a long

You can make the conversion of a String to long using the parseLong() method of Long class, or using the combination of the methods valueOf() and longValue(), also from Long class.


Similarly, going in the other direction, we can:

ENJOYING THIS POST?

Get More Benefits With LiveEdu Pro

Converting an integer to a String

See in the code below two ways to do the conversion of an integer to a string:


 

Converting a long to a String

You can do the conversion from long to String using the toString method of the class.


If you want to explore more about Java, visit our videos section! Below are some examples:

You can also follow some of the broadcasters who program in Java, the below:

How to convert String to int in Java java string int programming tipsAikar

How to convert String to int in Java java string int programming tipjennifer

Another cool way to find out interesting things about jQuery is to access our project page!

LiveEdu Pro
Check Out the LiveEdu Pro Subscription

  • Y. de Mello

    I thought of doing it another way, but this one seems simpler.

Read previous post:
c-quiz-of-the-day-1
Livecoding.tv Question of the Day: 07/10/2016

  Answer: The output will be: Although both variables are uninitialized, String is a reference type and DateTime is a value type. As a...

Close