提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将数组转换为字符串
//package com.nowjava; public class Main {/*来自 时 代 J a v a 公 众 号 - nowjava.com*/ public static void main(String[] argv) throws Exception { int[] array = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(toString(array)); } public static String toString(int[] array) { StringBuilder result = new StringBuilder("{"); if (array != null && array.length > 0) { for (int i = 0; i < array.length - 1; i++) { result.append(array[i] + ", "); } result.append(array[array.length - 1]); } result.append("}"); /* n o w j a v a . c o m - 时 代 Java 提 供 */ return result.toString(); } public static String toString(double[] array) { StringBuilder result = new StringBuilder("{"); if (array != null && array.length > 0) { for (int i