JAVA array to string
1. Problem
Convert the data of array type in JAVA to string type, and convert an integer array to string. For example, array {1, 2, 3}, the returned string is "[1, 2, 3]", pay attention to the comma The location and quantity.
2. Analysis
The string type in JAVA can realize a character and a number into a string through +=
3. Code
public class ARR {
public static void main(String[] args) {
int[] arrary = {
12, 19, 1, 25, 99, 52, 3, 67, 23, 15};
String RET = ToString(arrary);
System.out.println(RET);
}
public static String ToString(int [] arr){
String strarr = "[";
for (int i=0;i<arr.length;i++){
strarr += arr[i];
if (i!=arr.length-1){
strarr+=",";
}
}
strarr += "]";
return strarr;
}