Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.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_Eclipse - Fatal编程技术网

如何在Java中创建包含来自其他数组的数据的新数组?

如何在Java中创建包含来自其他数组的数据的新数组?,java,arrays,eclipse,Java,Arrays,Eclipse,如何从此阵列创建新阵列 String[] data = {"day: monday, color: green", "day: sunday, color: blue", "day: thursday, color: red"}; 看起来是这样的: String[] data = {"green", "blue", "red"}; 首先,创建相同大小的新数组: String[] colors = new String[data.length]; 然后迭代源数组,解析每个值并将其放入结果中。

如何从此阵列创建新阵列

String[] data = {"day: monday, color: green", "day: sunday, color: blue", "day: thursday, color: red"};
看起来是这样的:

String[] data = {"green", "blue", "red"};

首先,创建相同大小的新数组:

String[] colors = new String[data.length];
然后迭代源数组,解析每个值并将其放入结果中。有很多方法可以解析字符串。这取决于解析的强度。以下是最简单的方法:

for (int i = 0; i < data.length; i++) {
    String[] d = data[i].split(" ");
    colors[i] = d[d.length - 1];
}
for(int i=0;i

没有更多的评论。试着自己理解代码。这真是微不足道

首先,创建相同大小的新数组:

String[] colors = new String[data.length];
然后迭代源数组,解析每个值并将其放入结果中。有很多方法可以解析字符串。这取决于解析的强度。以下是最简单的方法:

for (int i = 0; i < data.length; i++) {
    String[] d = data[i].split(" ");
    colors[i] = d[d.length - 1];
}
for(int i=0;i

没有更多的评论。试着自己理解代码。这真是微不足道

首先,创建相同大小的新数组:

String[] colors = new String[data.length];
然后迭代源数组,解析每个值并将其放入结果中。有很多方法可以解析字符串。这取决于解析的强度。以下是最简单的方法:

for (int i = 0; i < data.length; i++) {
    String[] d = data[i].split(" ");
    colors[i] = d[d.length - 1];
}
for(int i=0;i

没有更多的评论。试着自己理解代码。这真是微不足道

首先,创建相同大小的新数组:

String[] colors = new String[data.length];
然后迭代源数组,解析每个值并将其放入结果中。有很多方法可以解析字符串。这取决于解析的强度。以下是最简单的方法:

for (int i = 0; i < data.length; i++) {
    String[] d = data[i].split(" ");
    colors[i] = d[d.length - 1];
}
for(int i=0;i

没有更多的评论。试着自己理解代码。这真是微不足道

我同意亚历克瑟关于自己解决问题的说法。下面是使用该方法设想for循环和解析操作的另一种方法。同样,请确保预先分配一个字符串数组来保存手头的结果,即:

String[]result=新字符串[data.length]

for(int i = 0; i < data.length; i++){

    // gets the substring starting on the 5th character
    String color = data[i].substring(5);

    // adds String to result
    result[i] = color;
}
for(int i=0;i
我同意亚历克斯关于自己解决问题的说法。下面是使用该方法设想for循环和解析操作的另一种方法。同样,请确保预先分配一个字符串数组来保存手头的结果,即:

String[]result=新字符串[data.length]

for(int i = 0; i < data.length; i++){

    // gets the substring starting on the 5th character
    String color = data[i].substring(5);

    // adds String to result
    result[i] = color;
}
for(int i=0;i
我同意亚历克斯关于自己解决问题的说法。下面是使用该方法设想for循环和解析操作的另一种方法。同样,请确保预先分配一个字符串数组来保存手头的结果,即:

String[]result=新字符串[data.length]

for(int i = 0; i < data.length; i++){

    // gets the substring starting on the 5th character
    String color = data[i].substring(5);

    // adds String to result
    result[i] = color;
}
for(int i=0;i
我同意亚历克斯关于自己解决问题的说法。下面是使用该方法设想for循环和解析操作的另一种方法。同样,请确保预先分配一个字符串数组来保存手头的结果,即:

String[]result=新字符串[data.length]

for(int i = 0; i < data.length; i++){

    // gets the substring starting on the 5th character
    String color = data[i].substring(5);

    // adds String to result
    result[i] = color;
}
for(int i=0;i