ironmantis7x
ironmantis7x

Reputation: 827

what does this mean in Java?

What does the following code do in Java:

for(JCheckBox check : Devices.selectedDevices)

I just want to be able to understand this and be a better developer

Upvotes: 0

Views: 122

Answers (3)

Mordechai
Mordechai

Reputation: 16234

Copy each element of Devices.selectedDevices, in JCheckBox check and process.

It is read: for each JCheckBox check in Devices.selectedDevices, do....

Upvotes: 0

Amit Deshpande
Amit Deshpande

Reputation: 19185

it is For-Each loop it is same as

for (Iterator<JCheckBox> i = Devices.selectedDevices.iterator(); i.hasNext(); )

Example:

// Returns the sum of the elements of a
 int sum(int[] a) {
    int result = 0;
    for (int i : a)
        result += i;
    return result;
}

Upvotes: 0

kosa
kosa

Reputation: 66637

This is called as for-each (or) enhanced for loop in java.

It means for each JCheckbox in selectedDevices array (or) collection.

Upvotes: 3

Related Questions