如何根据List中的可用值更改变量的值

时间:2016-04-22 21:39:20

标签: java arrays list arraylist

我需要您的帮助,根据列表中的可用值更改boolean变量的值。我定义了一个名为Student的类:

public class Student {
    private Integer id;//Getter and Setter
    private String name;//Getter and Setter
    private String location;//Getter and Setter
    private String remarks;//Getter and Setter
    private boolean disable;//Getter and Setter

    public Student(Integer id, String name, String location, String remarks, boolean disable){
                    this.id = id;
                    this.name = name;
                    this.location = location;
                    this.remarks=remarks;
                    this.disable=disable;
            }

默认情况下,bean中的disable值为true。在该计划中,我有两个列表employeeListselectedEmployeesemployeeList具有值,selectedEmployees列表具有所选值:

private List<Student> employeeList = new ArrayList<Student>();
private List<Student> selectedEmployees;
private boolean disable;

@PostConstruct
public void init() {
    //add Employees
    disable=true;
    Student w1 = new Student(111, "AAAA", "ZZZZ", "", disable);
    Student w2 = new Student(222, "CCCCC", "ZZZZZ", "OUT", disable);
    Student w3 = new Student(333, "BBBBBB", "YYYYYYY", "IN", disable);

    employeeList.add(w1);
    employeeList.add(w2);
    employeeList.add(w3);

}

但是,我有一个名为EnableInputText的方法,它将被调用以检查上述任何值是否在selectedEmployees列表中,然后它应该更改{{1}的值1}}变量到disable

false

但是使用上面的代码,我收到了错误:

  

java.lang.IndexOutOfBoundsException:Index:3,Size:3 at   java.util.ArrayList.RangeCheck(ArrayList.java:547)at   java.util.ArrayList.get(ArrayList.java:322)

1 个答案:

答案 0 :(得分:0)

selectedEmployees.get(j).setDisable(false);

我认为你的意思是用i而不是j代替那条线?

或反面可能:

employeeList.get(j).setDisable(false);