Java程序将一维和多维数组的数组转换为String
为了将数组转换为一维和二维数组,让我们首先创建一维和二维数组-
一维的
String str[] = {"p", "q", "r", "s", "t", "u", "v", "w","x", "y", "z"};
二维的
doubled [][]= {{1.2, 1.3, 2.1, 4.1},
{1.5, 2.3},
{2.5, 4.4},
{3.8},
{4.9},
{3.2, 2.1, 3.2, 7.2}
};
将数组转换为一维数组的字符串-
Arrays.toString(str);
将数组转换为二维数组的字符串-
Arrays.deepToString(d);
示例
import java.util.Arrays;public class Demo {
public static void main(String args[]) {
String str[] = {"p", "q", "r", "s", "t", "u", "v", "w","x", "y", "z"};
doubled [][]= {
{1.2, 1.3, 2.1, 4.1},
{1.5, 2.3},
{2.5, 4.4},
{3.8},
{4.9},
{3.2, 2.1, 3.2, 7.2}
};
System.out.println("One dimensional = "+Arrays.toString(str));
System.out.println("Two dimensional = "+Arrays.deepToString(d));
}
}
输出结果
One dimensional = [p, q, r, s, t, u, v, w, x, y, z]Two dimensional = [[1.2, 1.3, 2.1, 4.1], [1.5, 2.3], [2.5, 4.4], [3.8], [4.9], [3.2, 2.1, 3.2, 7.2]]
以上是 Java程序将一维和多维数组的数组转换为String 的全部内容, 来源链接: utcz.com/z/335326.html