Results 1 to 7 of 7

Thread: convert integer to string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118

    convert integer to string

    In java, how do you convert an integer to a string?

    1 = '1'

    Thanks

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: convert integer to string

    Code:
    int value=5;
    String str=Integer.toString(value);
    Last edited by ComputerJy; Sep 23rd, 2006 at 09:34 PM. Reason: CornedBee is right
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: convert integer to string

    I alwys used following as ComputerJy used,

    int int_value=100;
    String string_value=Integer.toString(int_value);
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: convert integer to string

    > String str=""+5;

    Not a good idea. This creates a temporary StringBuilder.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: convert integer to string

    Quote Originally Posted by CornedBee
    > String str=""+5;

    Not a good idea. This creates a temporary StringBuilder.
    Yeah I know, but there are people who still do it that way
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: convert integer to string

    Quote Originally Posted by ComputerJy
    Yeah I know, but there are people who still do it that way
    Like me, but being lazy is my excuse.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: convert integer to string

    Quote Originally Posted by ComputerJy
    Yeah I know, but there are people who still do it that way
    All the more reason not to show new people this approach, or say that it's not good, no?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width