如何从一个数组迭代值并将其保存到另一个数组 [英] how to iterate value from one array and save it to another array
本文介绍了如何从一个数组迭代值并将其保存到另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static void main(String[] args) {
TestSection ts = new TestSection();
Section s = new Section();
String[] str = new String[] { "Jack:90:92:90:90:90",
"Shazz:88:45:76:60:44", "Nazz:74:44:56:64:52" };
s = ts.makeSections(str);
System.out.println(s.nameofA());
}
public Section makeSections(String[] studentsData) {
Section sc = new Section();
sc.student = new Student[studentsData.length];
String[] studentsDta = new String[3];
for (int i = 0; i < studentsData.length; i++) {
studentsDta = studentsData[i].split(":");
sc.student[i] = new Student();
sc.student[i].name = studentsDta[0];
sc.student[i].marks = studentsDta[];
}
return sc;
}
这里 sc.student [i] .marks
是一个数组i想要在其中存储以上学生标记
here sc.student[i].marks
is an array i want to store above student marks in it
推荐答案
这样的事情:
Something like this:
int j;
sc.student[i].marks = new int[studentDTA.length-1];
for (j = 0; j < (studentDTA.length - 1 ); j++)
{
sc.student[i].marks[j] = integer.parseInt(studentDTA[j+1]);
}
这篇关于如何从一个数组迭代值并将其保存到另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文