O'Reilly logo

Core Java® Volume II—Advanced Features, Ninth Edition by Gary Cornell, Cay S. Horstmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.5.2. Indexed Properties

An indexed property specifies an array. With an indexed property, you need to supply two pairs of get and set methods: one for the array and one for individual entries. They must follow this pattern:

Type[] getPropertyName() void setPropertyName(Type[] newValue) Type getPropertyName(int i) void setPropertyName(int i, Type newValue)

For example, the FilePickerBean uses an indexed property for the file extensions. It provides these four methods:

private String[] extensions; . . . public String[] getExtensions() { return extensions; } public void setExtensions(String[] newValue) { extensions = newValue; } public String getExtensions(int i) {    if (0 <= i && i < extensions.length) return extensions[i]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required