Arrays and Javabeans

Published: Tuesday, 21 September 2004

Array properties can be stored with the same getters and setters, but can also have indexed properties.

  public class StringArrayBean {

    private String name;
    private String[] ids;
  
    public String getName() {
      return name;
    }
  
    public void setName(String name) {
      this.name = name;
    }
  
    public String[] getIds() {
      return ids;
    }
  
    public String getIds(int index) {
      return ids[index];
    }
  
    public void setIds(String[] ids) {
      this.ids = ids;
    }
    public void setIds(int index, String s) {
      this.ids[index] = s;
    }
  }