Results 1 to 14 of 14
  1. #1
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default string conversion??

    while getting input from console we use Interger.parseInt(string) to convert string to integer value,,,


    i want the reverse proces....


    i have an integer value,,,, but i need to pass only a string value to a method... so i have to convert by integer value to string,,,

    how to convert integer value to string???

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Read the API docs for Integer.

    If you have an Integer, toString

    If you have an int, new Integer(int).toString or "" + int or Integer.toString(int) or Integer.toString(int, radix).

    Gods, why is it so hard for people to read the API docs. It could save them (and most definately us, except the humiliation) so much trouble, humiliation, and irritation.
    Last edited by masijade; 09-18-2008 at 10:30 AM.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    nishant is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    hi....how r u. might this work for u


    int x = 97;//suppose
    String a = Integer.toString(x);
    System.out.println(a);



    OR


    int x = 97;//suppose
    String a = String.valueOf(x)
    System.out.println(a);



    got alot of ways to convert Int to String

  5. #5
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    6

    Default

    There is a lot of way matey . . . ^_^

    here i'll modify your first code. try it, then if problem arises you can ask for opinion ^_^

    int x = 97;
    String a = x.toString();
    System.out.println(a);
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  6. #6
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Read the API docs for Integer.

    If you have an Integer, toString

    If you have an int, new Integer(int).toString or "" + int or Integer.toString(int) or Integer.toString(int, radix).

    Gods, why is it so hard for people to read the API docs. It could save them (and most definately us, except the humiliation) so much trouble, humiliation, and irritation.
    if u really want to help, u give answers,,, dont make us fools..

    y u getting irritated alwys...

    u answers question tat r to ur level,,, but dont underestimate others..

    u read only advanced java forums

  7. #7
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    Quote Originally Posted by nishant View Post
    hi....how r u. might this work for u


    int x = 97;//suppose
    String a = Integer.toString(x);
    System.out.println(a);



    OR


    int x = 97;//suppose
    String a = String.valueOf(x)
    System.out.println(a);



    got alot of ways to convert Int to String
    thanxxxxxxxxxxxx

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Quote Originally Posted by j2vdk View Post
    if u really want to help, u give answers,,, dont make us fools..

    y u getting irritated alwys...

    u answers question tat r to ur level,,, but dont underestimate others..

    u read only advanced java forums

    "New to Java" does not mean "do this for me as I'm too lazy to even attempt to look it up". The API docs is always the first place to look. You new that you were concerned with Integer and String, so read the API docs for those two classes. How is that soooooo hard to do?

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Quote Originally Posted by j2vdk View Post
    thanxxxxxxxxxxxx
    And two minutes looking at the docs yourself would have told you this. Instead you spent a couple of hours waiting on someone else to look it up for you.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Eku View Post
    There is a lot of way matey . . . ^_^

    here i'll modify your first code. try it, then if problem arises you can ask for opinion ^_^

    int x = 97;
    String a = x.toString();
    System.out.println(a);
    Ya, I agreed with you. The way should be like this. Why did you think in this way, in simple word I'm not recommended the use of wrapper classes mix up.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by j2vdk View Post
    if u really want to help, u give answers,,, dont make us fools..

    y u getting irritated alwys...

    u answers question tat r to ur level,,, but dont underestimate others..

    u read only advanced java forums
    First of all, stop short messaging in the forum. May be others couldn't read it correctly.

    And also try to respect others as well, doesn't matter he/she is a senior member or not, keen on Java or not.

    What masijade says you, is first try do something yourself. As he said if you read the doc no need to wait someone replaying your question. So why did you get anger with that replay? Please keep in mind that, before asking any question try something yourself first. It doesn't make sense that you are a Java newbie or not.

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    There is, of course, also String.valueOf(int) or String.valueOf(Integer). Another thing that can be found out in about 30 secs in the API docs.

  13. #13
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    First of all, stop short messaging in the forum. May be others couldn't read it correctly.

    And also try to respect others as well, doesn't matter he/she is a senior member or not, keen on Java or not.

    What masijade says you, is first try do something yourself. As he said if you read the doc no need to wait someone replaying your question. So why did you get anger with that replay? Please keep in mind that, before asking any question try something yourself first. It doesn't make sense that you are a Java newbie or not.
    dont short message here

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. String to Integer Conversion in JSP
    By vinikz in forum New To Java
    Replies: 8
    Last Post: 11-10-2010, 02:45 PM
  2. bytearray to string conversion
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 10:39 AM
  3. Method for String to int conversion
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:35 PM
  4. String to Integer conversion
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 03:59 PM
  5. String to Date conversion
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •