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 1036151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:39:21+00:00 2026-05-16T14:39:21+00:00

According to the tool PMD, the following is a bad practice: String s =

  • 0

According to the tool PMD, the following is a bad practice:

String s = "" + 123; // bad 
String t = Integer.toString(456); // ok 


This is an inefficient way to convert any type to a `String`.

Why is it a bad thing to do?

  • 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-16T14:39:22+00:00Added an answer on May 16, 2026 at 2:39 pm
    String s = "" + 123; // bad     
    String t = Integer.toString(456);
    

    Will be compiled to:

    String s = "123";
    String t = Integer.toString(456);
    

    so: “” +123 is obvious slightly better! Checked with JAD

    public static void main(String args[])
    {
    //    0    0:ldc1            #16  <String "123">
    //    1    2:astore_1
    //    2    3:sipush          456
    //    3    6:invokestatic    #18  <Method String Integer.toString(int)>
    //    4    9:astore_2
    //    5   10:getstatic       #24  <Field PrintStream System.out>
    //    6   13:new             #30  <Class StringBuilder>
    //    7   16:dup
    //    8   17:aload_1
    //    9   18:invokestatic    #32  <Method String String.valueOf(Object)>
    //   10   21:invokespecial   #38  <Method void StringBuilder(String)>
    //   11   24:aload_2
    //   12   25:invokevirtual   #41  <Method StringBuilder StringBuilder.append(String)>
    //   13   28:invokevirtual   #45  <Method String StringBuilder.toString()>
    //   14   31:invokevirtual   #48  <Method void PrintStream.println(String)>
    //   15   34:return
    }
    

    EDIT:

    For non-constant values:

    int i = 123;
    String s = (new StringBuilder()).append(i).toString();
    String t = Integer.toString(i);
    System.out.println((new StringBuilder(String.valueOf(s))).append(t).toString());
    
        public static void main(String args[])
        {
        //    0    0:bipush          123
        //    1    2:istore_1
        //    2    3:new             #16  <Class StringBuilder>
        //    3    6:dup
        //    4    7:invokespecial   #18  <Method void StringBuilder()>
        //    5   10:iload_1
        //    6   11:invokevirtual   #19  <Method StringBuilder StringBuilder.append(int)>
        //    7   14:invokevirtual   #23  <Method String StringBuilder.toString()>
        //    8   17:astore_2
        //    9   18:iload_1
        //   10   19:invokestatic    #27  <Method String Integer.toString(int)>
        //   11   22:astore_3
        //   12   23:getstatic       #32  <Field PrintStream System.out>
        //   13   26:new             #16  <Class StringBuilder>
        //   14   29:dup
        //   15   30:aload_2
        //   16   31:invokestatic    #38  <Method String String.valueOf(Object)>
        //   17   34:invokespecial   #44  <Method void StringBuilder(String)>
        //   18   37:aload_3
        //   19   38:invokevirtual   #47  <Method StringBuilder StringBuilder.append(String)>
        //   20   41:invokevirtual   #23  <Method String StringBuilder.toString()>
        //   21   44:invokevirtual   #50  <Method void PrintStream.println(String)>
        //   22   47:return
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this schema VS2010 Premium and Ultimate has a tool for checking Code
according to this description I just created an nine-patch image. I named it androidRow.9.png
According to this question Raphael - event when mouse near element i create a
According to this , ActiveRecord first generates the SQL: SELECT * FROM clients LIMIT
According to this http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html article, I defnitely should. Quote Gentle, yet insistent executive summary:
I am checking this PHP quality control tool: PHP_CodeSniffer In its documentation page Example
Do you know a tool that can accomplish this? or some dirty batch command
Why the following assembly code is an anti-debugging tool? l1: call l3 l2: ;some
So according to the w3c validation tool, wrapping a div (especially one which floats)
According to everything I've seen, the following C++ program should be displaying a balloon

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.