Java convert an Int to a String

Discussion in 'Java' started by tombezlar, Mar 24, 2021.

  1. tombezlar

    tombezlar New Member

    Joined:
    Mar 22, 2021
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Here are 3 ways to convert an int to a String

    String s = String.valueOf(n);
    String s = Integer.toString(n);
    String s = "" + n;

    I understand what we did for the first and second methods. But can someone please explain what does 3rd method do? In other words, how does "" convert integer into string?
    Thanks
     
  2. Lexxxis

    Lexxxis New Member

    Joined:
    Mar 23, 2021
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Female
    Hey, @tombezlar

    Are you sure that the 3d method is needed in that case? As far as I understood, it's a combo of an empty string and "n" (in a nutshell). The function is the same as in both above.
     
  3. Lexxxis

    Lexxxis New Member

    Joined:
    Mar 23, 2021
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Female
    I guess that you may dig deeper into the topic if needed, for example, check some articles on CodeGym blog. However, this one isn't the easiest part of Java, for sure.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice