Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:31:05+00:00 2026-05-23T17:31:05+00:00

I can convert an integer into string using String s = + 4; //

  • 0

I can convert an integer into string using

String s = "" + 4; // correct, but poor style
or
String u = Integer.toString(4); // this is good

I can convert a double into string using

String s = "" + 4.5; // correct, but poor style
or
String u = Double.toString(4.5); // this is good

I can use String s = "" + dataapproach to convert either an int or double into String. While If I wants to use the other approach using toString() I have to use the Wrapper class of each data type. Then why in some books it is mentioned that the first approach is poor one while the second one is the better. Which one is the better approach and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:31:05+00:00Added an answer on May 23, 2026 at 5:31 pm

    I would use

    String.valueOf(...)
    

    You can use the same code for all types, but without the hideous and pointless string concatenation.

    Note that it also says exactly what you want – the string value corresponding to the given primitive value. Compare that with the "" + x approach, where you’re applying string concatenation even though you have no intention of concatenating anything, and the empty string is irrelevant to you. (It’s probably more expensive, but it’s the readability hit that I mind more than performance.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MSSQL you can convert a string into an integer like this: CONVERT(INT, table.column)
Can I convert a string representing a boolean value (e.g., 'true', 'false') into an
Can we convert a hex string to a byte array using a built-in function
I found the code to convert a hexadecimal string into a signed int using
How can i convert an integer ranging from 0 to 255 to a string
There's this program, pdftotext, that can convert a pdf file to a text file.
How can I convert a character to its ASCII code using JavaScript? For example:
How can I convert a JavaScript string value to be in all lowercase letters?
Can anyone beat the performance of my integer to std::string code, linked below? There
I need an encoder that can convert mp3 files to he-aac (aka aac+). So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.