Reputation: 827
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
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
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