Java数组怎么初始定义不定的长度?答:这个数组int newarr[]=null你是声明为空的肯定会报错啊。有两个方法第一:你先循环遍历int oldarr[]={1,3,5,0,0,6,7,8,0,9,0,5,6}这个数组看它有几个数是零在添加在newarr中。第二:你可以不要用数组做用集合List集合来做方便多了不要考虑数组长度。
JAVA创建一个数组a[]={1,2,3,4,5},b[]={6,7,8,9,10}, 声明一个数组c...答:是要合并么?public class $ { public static void main(String[] args) { int[] a = { 1, 2, 3, 4, 5 }; int[] b = { 6, 7, 8, 9, 10 }; int[] c = new int[a.length + b.length]; int index = 0; for (int i : a) { c[index++] = ...
java 如何设置动态数组?答:public class Test1{ String a = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T";String[] myArray = null;public String[] getString(){ myArray = a.split(",");} }