devxlogo

Converting Numbers to Strings

Converting Numbers to Strings

"" + set.size()new Integer(set.size()).toString()

The return type of the Set.size() method is int, but it is desired a conversion to String. These two lines do the conversion, but the first use the penalty of a concatenation operation ((new StringBuilder().append(i).toString())) and the second one creates an intermediate Integer wrapper. So, the right way to convert numbers to Strings is:

Integer.toString(set.size())
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist