How to convert String to int in Java

How to convert String to int in Java

Home Forums JAVASCRIPT How to convert String to int in Java

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33239
    SEO hacker
    Participant

    I want to convert a string to an integer / int in Java. The string is numeric but i want to use it as number so that i can perform arithmetic operations on it. For example, the given string is “129 x 590” after replacing “x” it becomes “129590” and now want the result as number = 129590.

    #33262
    HARPAL SINGH
    Keymaster

    Here is the simple way to convert your string in to Int :

    str = “129590”

    int new = Integer.parseInt(str);

    or

    Integer x = Integer.valueOf(str);

    valueOf ()returns a new or cached instance of java.lang.Integer
    parseInt() returns primitive int.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.