Java 需要帮助在处理过程中将整数数组添加到数组列表中吗
好的。。。所以我在一个项目的中间,我撞到了一堵墙。如果有人能解释如何将整数数组添加到整数数组的数组列表中,我将不胜感激。这是在处理中,更具体地说是javascript版本。我已经测试过了,所有的东西都能正常工作到'symbols.get(I).add(tempArray)。如果我在该行之前打印tempArray,它会给出“61016620”,这是应该的。不,不仅仅是println(符号)语句,我还尝试了“println”(“blah”);”而这并没有出现在输出中,因此.get行出现了一些错误Java 需要帮助在处理过程中将整数数组添加到数组列表中吗,java,javascript,arrays,arraylist,processing,Java,Javascript,Arrays,Arraylist,Processing,好的。。。所以我在一个项目的中间,我撞到了一堵墙。如果有人能解释如何将整数数组添加到整数数组的数组列表中,我将不胜感激。这是在处理中,更具体地说是javascript版本。我已经测试过了,所有的东西都能正常工作到'symbols.get(I).add(tempArray)。如果我在该行之前打印tempArray,它会给出“61016620”,这是应该的。不,不仅仅是println(符号)语句,我还尝试了“println”(“blah”);”而这并没有出现在输出中,因此.get行出现了一些错误 s
size(850,250);
String[] myList = new String[100];
ArrayList<Integer[]> symbols = new ArrayList<Integer[]>();
int[] tempArray = new int[];
String numbers = ("6,10,16,10,16,20\n1,25,21,13,3,15\n6,5,20,6,21,20");
myList = (split(numbers, "\n"));
int j = myList.length();
for(int i = 0; i<j; i++)
{
tempArray = int(split(myList[i], ','));
symbols.get(i).add(tempArray);
}
println(symbols);
尺寸(850250);
字符串[]myList=新字符串[100];
ArrayList符号=新的ArrayList();
int[]临时数组=新int[];
字符串编号=((“6,10,16,16,20\n1,25,21,13,3,15\n6,5,20,6,21,20”);
myList=(拆分(数字,“\n”);
int j=myList.length();
对于(int i=0;i,首先使用ArrayList上的get方法获取整数数组,然后添加[index]以指定在返回数组的哪个索引处添加什么
symbols.get(i)[a] = tempArray[a];
有一些错误。关键的一点是,您不能将int[]
添加到需要Integer[]
的列表中。请参阅代码上的注释:
void setup()
{
size(850, 250);
String[] myList = new String[100];
ArrayList<Integer[]> symbols = new ArrayList<Integer[]>();
// you can't init an array without a inintial dimension
//int[] tempArray = new int[];
int[] tempArray;
String numbers = ("6,10,16,10,16,20\n1,25,21,13,3,15\n6,5,20,6,21,20");
myList = (split(numbers, "\n"));
//length is not a method... no parenthesis here
//int j = myList.length();
int j = myList.length;
for (int i = 0; i<j; i++)
{
tempArray = int(split(myList[i], ','));
// you cant add an int[] to an Integer[] arrayList
// you gotta either change the arraylist type or convert the ints to Integers
// also just use .add(). not get().add() it's a one dimension list
symbols.add(parseArray(tempArray));
println(symbols.get(i) );
println("--");
}
}
//convenience function..
Integer[] parseArray(int[] a) {
Integer[] b = new Integer[a.length];
for (int i = 0; i<a.length; i++) {
b[i] = Integer.valueOf(a[i]);
}
return b;
}
void setup()
{
尺寸(850250);
字符串[]myList=新字符串[100];
ArrayList符号=新的ArrayList();
//如果没有初始维度,就无法初始化数组
//int[]临时数组=新int[];
int[]临时数组;
字符串编号=((“6,10,16,16,20\n1,25,21,13,3,15\n6,5,20,6,21,20”);
myList=(拆分(数字,“\n”);
//长度不是一个方法…这里没有括号
//int j=myList.length();
int j=myList.length;
对于(inti=0;iDo),您的意思是没有执行println(符号)并且没有任何异常?
for(int a = 0; a < tempArray.length(); a++)
{
symbols[i][a] = tempArray[a];
}
println(symbols);
symbols.get(i)[a] = tempArray[a];
void setup()
{
size(850, 250);
String[] myList = new String[100];
ArrayList<Integer[]> symbols = new ArrayList<Integer[]>();
// you can't init an array without a inintial dimension
//int[] tempArray = new int[];
int[] tempArray;
String numbers = ("6,10,16,10,16,20\n1,25,21,13,3,15\n6,5,20,6,21,20");
myList = (split(numbers, "\n"));
//length is not a method... no parenthesis here
//int j = myList.length();
int j = myList.length;
for (int i = 0; i<j; i++)
{
tempArray = int(split(myList[i], ','));
// you cant add an int[] to an Integer[] arrayList
// you gotta either change the arraylist type or convert the ints to Integers
// also just use .add(). not get().add() it's a one dimension list
symbols.add(parseArray(tempArray));
println(symbols.get(i) );
println("--");
}
}
//convenience function..
Integer[] parseArray(int[] a) {
Integer[] b = new Integer[a.length];
for (int i = 0; i<a.length; i++) {
b[i] = Integer.valueOf(a[i]);
}
return b;
}
void setup()
{
size(850, 250);
String[] myList = new String[100];
ArrayList<int[]> symbols = new ArrayList<int[]>();
// you can't init an array without a inintial dimension
//int[] tempArray = new int[];
int[] tempArray;
String numbers = ("6,10,16,10,16,20\n1,25,21,13,3,15\n6,5,20,6,21,20");
myList = (split(numbers, "\n"));
//length is not a method... no parenthesis here
//int j = myList.length();
int j = myList.length;
for (int i = 0; i<j; i++)
{
tempArray = int(split(myList[i], ','));
symbols.add(tempArray);
println(symbols.get(i) );
println("--");
}
}