有一个student类,里面又包含了另一个score类,现在我通过方法得到了一个List<student>,请问我怎样才能得到List<score>呢?

解决方案 »

  1.   


    就是student类里面有一个属性是score类
      

  2.   

    List<Score> scores= new ArrayList<Score>();
    List<student> students = new ArrayList<Score>();
    for(Student s:students){
    scores.add(s.getScore());
    }
      

  3.   

    student类中有没有那个score类的set和get方法,是一对多的关系?是的话,那个score在student里的设置应该是List<score> list;这样来定义这个属性,如果不是的话,那就都取出来,然后新建一个List,add进去就可以了