【发布时间】:2020-01-10 19:41:51
【问题描述】:
我正在尝试用 Java 编写一些围绕 Char 数组的代码并且有一些问题,从下面的第一个开始。如果可能在代码中的任何地方,我更喜欢使用 Java 8 并避免使用循环。请帮忙,谢谢。
问题一:打印出一个字符数组的最大容量。
// Create a character array that can hold a max of 10 elements and copy
over the contents from another character array.
char[] charArr1 = {'A','B','C'};
char[] charArr2 = new char[10];
charArr2 = charArr1.clone();
// I wanted the result below to be 10, but the output was 3.
System.out.println(charArr2.length);
【问题讨论】:
-
charArr2 = ...是一个赋值(见stackoverflow.com/questions/3858510/assigning-in-java),所以new char[10]消失了
标签: java