我正在學習課程,想出了這種情況。這是我的代碼。從單個方法返回一個ArrayList和int值。可能嗎?
public static ArrayList<Student> checkPresent(String unitID, String week){
int present = 0;
ArrayList<Student> studentDetails = Student.getStudentDetails();
ArrayList<AttendanceLog> pickedList = AttendanceLog.pickFromAttendanceLog(unitID, week);
for(Student student : studentDetails){
student.setPresent("N");
for(AttendanceLog attendance : pickedList){
if(student.getStudentNo().equals(attendance.getStudentID())){
student.setPresent("Y");
present++;
}
}
}
return studentDetails;
}
我只返回ArrayList
但我也想要得到的整數值present
。可能嗎?或者我該如何取得整數值?
你可以在一個類中封裝arraylist和integer並返回它的對象 – Hemang
[如何從Java方法返回多個對象?](http://stackoverflow.com/questions/457629/how-返回多個對象從一個Java方法) – ctomek