Languages
[Edit]
EN

Java - convert int to String

7 points
Created by:
Brett4
465

In Java, we can convert int to String in couple of different ways.

Short solutions:

1. Using String.valueOf()

Edit

Output:

2. Using Integer.toString()

Edit

Output:

3. Using "" + 123

Edit

Output:

4. Using String.format()

Edit

Output:

5. Using StringBuilder

Edit

Output:

The same can be applied to StringBuffer

6. Using DecimalFormat

Edit

Output:

7. Using DecimalFormat with floating point pattern

Edit

Output:

References

Edit
  1. Integer.toString(int)
  2. String.valueOf(int)
  3. String.format(java.lang.String,java.lang.Object...)
  4. StringBuilder.append(int)
  5. DecimalFormat.format(long)
  6. Type conversion - wik

Post summary image

Edit

Java - convert int to String - Post summary image - dirask.com - https://dirask.com/q/X13b9j

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java conversion

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join