如何在Array-list上保存对象的内容?

时间:2014-12-23 06:13:54

标签: arraylist

如何在Array-list上添加对象的内容?

感谢,

这是我的代码

    ArrayList soft1=new ArrayList();



    if ("Software".equals((String)major.getSelectedItem())){

        add(p2s,BorderLayout.CENTER);
        p2s.setVisible(true);
        p2n.setVisible(false);
        p2sc.setVisible(false);
        if (e.getSource()==save){
            String id1=id.getText();
            String name1=name.getText();
            String gender11=(String)gender1.getSelectedItem();
            String major1=(String)major.getSelectedItem();

            StudentSoftware software=new StudentSoftware( studentID, studentName, gender, studentMajor, course1, course2,  course3, mark1, mark2, mark3);

1 个答案:

答案 0 :(得分:1)

您需要将POJO类的Arraylist声明为ArrayList<StudentSoftware> soft = new ArrayList<StudentSoftWare>()。然后将StudentSoftware初始化为StudentSoftware student = new StudentSoftware(),将设置值设置为POJOClass为student .setid(id),然后在POJOclass中生成setter和getter。最后将POJOclass对象添加到Arraylist中soft.add(student)

我觉得它对你有用......