I\'m confused a bit. I couldn\'t find the answer anywhere ;(
I\'ve got an String array:
String[] arr = [\"1\", \"2\", \"3\"];
then
Here is a way to do it: Arrays.toString(array).substring(1,(3*array.length-1)).replaceAll(", ","");
Here is a demo class:
package arraytostring.demo;
import java.util.Arrays;
public class Array2String {
public static void main(String[] args) {
String[] array = { "1", "2", "3", "4", "5", "6", "7" };
System.out.println(array2String(array));
// output is: 1234567
}
public static String array2String(String[] array) {
return Arrays.toString(array).substring(1, (3 * array.length - 1))
.replaceAll(", ", "");
}
}
Scala makes this easier, cleaner and safer:
scala> val a = Array("1", "2", "3")
a: Array[String] = Array(1, 2, 3)
scala> val aString = a.mkString
aString: String = 123
scala> println(aString)
123