我可以选择添加新行来添加学生详细信息。
<table>
Name:<tr><td><input type="text" name="sname"></td></tr>
Id:<tr><td><input type="text" name="sid></td></tr>
</table>
<input type="button value="Add new row">
现在,我想将所有行数据存储在数组列表中。如何将数组存储在多行中的数组列表中?
array_list:{["Pooja",1]["Priya,2]}
答案 0 :(得分:0)
让学生班级有字段姓名&amp; ID。并将此对象存储到ArrayList中。
答案 1 :(得分:0)
public class Student {
private String name;
private int id;
public Student(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public String toString() {
return String.format("[\"%s\", %s]", this.name, this.id);
}
}
List<Student> students = new ArrayList<>();
students.add(new Student(1, "Pooja"));
students.add(new Student(2, "Priya"));
// {["Pooja", 1],["Priya", 2]}
System.out.print(students.stream().map(Object::toString).collect(Collectors.joining(",", "{", "}")));