I have an integer array that keeps binary numbers 0 and 1 in itself. I want to convert my integer array to a string variable in java. How can I do it?
Tell me more
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
closed as off-topic by Kevin Panko, Shankar Damodaran, LaurentG, Dave A, M. Deinum Nov 27 '13 at 7:18
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist" – Kevin Panko, Shankar Damodaran, LaurentG, Dave A, M. Deinum
Probably Arrays.toString(int[]) is what you are looking for.
This should print [1, 2, 3]. Here is a fiddle for it. |
|||
|
If you don't mind having brackets around your string, and your numbers separated by a comma, you can use |
|||
|
This is one way of doing it:
|
|||
|
You can also do it manually like this
That would be especially useful if you want to use a special format. Above example will produce strings like And a fiddle. Edit: oops, |
||||
|
Arrays
class? Its an Integer array. – Rohit Jain Nov 20 '12 at 16:41Array
can be directly converted to string usingArrays.toString
method, or, it can be iterated upon, and each integer can be appended into aStringBuilder
. So, Integer class really doesn't come into action in this case. I hope that makes it clear. – Rohit Jain Nov 20 '12 at 17:34