0

How can I do this Python trick in Java?

>>> l = [1,2,3,4,5]
>>> print ' '.join(l)
1 2 3 4 5

This doesn't apply to Strings only. I am using generics and need to print any kind of value in the Array.

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
  • If you can't figure out the duplicate link, drop a comment and someone will repoen the question. – Tim Biegeleisen Apr 01 '17 at 23:36
  • This doesn't apply to Strings only. I am using generics and need to print any kind of value in the Array. – JacobIRR Apr 01 '17 at 23:37
  • 1
    Here's the thing, the final join step requires concatening everything with space, which is a string. So I would say that you should first convert the array elements to string before joining. – Tim Biegeleisen Apr 01 '17 at 23:39
  • Ah, right. And that would hold true even if I joined with an empty string. Thanks. – JacobIRR Apr 01 '17 at 23:43

0 Answers0