In need of some java help

destined

Senior member
Apr 17, 2004
490
0
0
lets say I have 4 digits. 1, 2, 3, 4, how can I put them together as one whole digit 3412?
 

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
Are they strings or ints? If they're strings you can go string1+string2 to concatenate. If they're not strings you can use Integer.toString() to convert them.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
To further Atheus' point, the most compact way I can think to do it is: "" + 3 + 4 + 1 + 2. A bit ugly though, as the empty string is meaningless and distracting.

You can concatenate an integer (or pretty much anything) to a string and it will be coerced. Non-primitive types get their toString() method called; primitive types are probably replaced with calls like Integer.toString().