Java: Convert Primitive Type int to String
Date: 2014-06-09 |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
**Problem: **I have a primitive int that I want to turn into a string
Solution:
Eclipse hates it when you try to pass in a primitive int as a String. You’ll get warnings if you try to cast it to a string or call .toString() on it.
The easiest way to get around this is to simply concatenate “” at the end. This’ll allow methods/variables to read the primitive int as a string.
Example:
int aNum = 9;
String bNum = aNum + “”;
Want more like this?
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.