如何从该数组创建一个新数组
String[] data = {"day: monday, color: green", "day: sunday, color: blue", "day: thursday, color: red"};
看起来像这样:
String[] data = {"green", "blue", "red"};
最佳答案
我同意AlexR关于自己解决问题的说法。这是使用substring()方法设想for循环和解析操作的另一种方法。同样,请确保预先分配一个String数组以预先保存结果,即:String[] result = new String[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;
}