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

  • Home
  • SEARCH
  • 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 6683375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:48:52+00:00 2026-05-26T04:48:52+00:00

we often come across a scenario where in we need to pass a String

  • 0

we often come across a scenario where in we need to pass a String representation of a primitive and More often then not we use

  WrapperClass.toString() ;

and sometimes we usually write

  i + "";

if we check to toString implementation of any wrapper class it creates a new String object every time we call it. and same is also true for primitive + “” (as Concatenation during runtime will create new String Object)

So is there any difference between them or they are just an alternative ways to convert a primitive to a String object;

  • 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-26T04:48:52+00:00Added an answer on May 26, 2026 at 4:48 am

    Good intentions.

    Writing i + "";, you’re possibly leaving it up to your code’s future maintainer (which could very well be you) to figure out what that output will be.

    WrapperClass.toString(); is more explicit and, although more verbose, its intentions are clearer. Besides, weak typing isn’t what you’d normally see in Java, so I suggest you stick to writing idiomatic Java code.

    After compilation, emitted bytecode will most likely be the same or similar. After jitting and during runtime, you can expect the differences to be effectively nullified.

    So, at the end, it’s a matter of style, although I’d suggest using the more verbose version of your code.

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

Sidebar

Related Questions

I often come across situations when I need to use the same variable but
Occasionally I come across methods with an uncomfortable number of parameters. More often than
More often than I'd have hoped I seem to come across method/property definitions in
I often come across a scenario where I have two collections of objects (either
I often come across web applications that expose internal database primary keys through forms
I often come across the term 'named type' in C#. What does it mean?
Over the last few months I've often come across the same Design obstacles when
When using JDBC, I often come across constructs like ResultSet rs = ps.executeQuery(); while
when i read through source files of opensource projects i often come across some
Quite often I come across a nice looking or functional website, and wonder what

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.