Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用字符串数组中的字符串初始化新对象_Java_Arrays_String_Initialization - Fatal编程技术网

Java 使用字符串数组中的字符串初始化新对象

Java 使用字符串数组中的字符串初始化新对象,java,arrays,string,initialization,Java,Arrays,String,Initialization,我想创建一个存储“名称”的字符串数组;这些名称应该用于创建由数组中字符串命名的新ArrayList 这样不行。有没有办法解决这个问题,或者你能解释一下为什么不可能 public String combiTop [] = {"1er","2er","3er","4er","5er","6er"}; topRowValue = new ArrayList<>(); for (int i = 0; i < combiTop.length; i++) {

我想创建一个存储“名称”的
字符串
数组
;这些名称应该用于创建由数组中字符串命名的新ArrayList

这样不行。有没有办法解决这个问题,或者你能解释一下为什么不可能

public String combiTop [] = {"1er","2er","3er","4er","5er","6er"};

topRowValue = new ArrayList<>();
        for (int i = 0; i < combiTop.length; i++) {
            ArrayList<Integer> combiTop[i] = new ArrayList<>();
            for (int j = 0; j < 6; j++) {
                combiTop[i].add(-1);
            }
            topRowValue.add(combiTop[i]);
        }
publicsstringcombitop[]={“1er”、“2er”、“3er”、“4er”、“5er”、“6er”};
topRowValue=新的ArrayList();
对于(int i=0;i
在Java中,同一函数中的变量是固定类型的,因此不能将ArrayList值分配给字符串数组或其中的值。因此:

String combiTop; //you don't have to assign values in your demonstration

ArrayList<String> = new ArrayList<String>(combiTop.length);
for (String s : combiTop) { // this iterates through each value in the array
    topRowValue.add(s);
}
String-combiTop//您不必在演示中指定值
ArrayList=新的ArrayList(战斗段长度);
对于(字符串s:combiTop){//这将遍历数组中的每个值
topRowValue。添加;
}

我不确定这里问的是什么,你只是想把数组转换成一个列表吗?我想在数组组合中使用字符串,用这些名称创建新的对象(ArrayList)。我仍然不明白,你能给出一个期望结果的例子吗?私有字符串名称[]={“max”、“tom”、“paul”};ArrayList名称[1]=新的ArrayList();//它应该创建一个新的ArraList,但是您不能用动态变量名定义变量,这似乎是您在这里尝试的。