Java: Convert Primitive Type int to String
Date: 2014-06-09 |
**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 / easiest way to support my work is by subscribing for future updates and sharing with your network.