java.util包的Arrays类toString()为所有原始数据类型和对象提供方法。这些方法接受一个数组并返回其字符串表示形式。
因此,要将数组转换为字符串,请将所需的数组传递给此方法。
import java.util.Arrays;
public class ArrayToString {
public static void main(String args[]) throws Exception {
int[] myArray = {23, 93, 56, 92, 39};
String str = Arrays.toString(myArray);
System.out.println(str);
}
}输出结果
[23, 93, 56, 92, 39]