Skip to main content

Question about the FOR loops ...

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
sam_sepassi
Offline
Joined: 2010-12-16

Does anyone encounter any for loops like FOR(a:b){ ---- } in java ?
for example
public class MyProgram {
private Vector<AbstractTask> tasks = new Vector<AbstractTask>();
public MyProgram() {
tasks.add(new MyTask("Task1"));
tasks.add(new MyTask2("Task2"));
tasks.add(new MyTask2("Task3"));
}
public void processTaskList() {
ProgressContributor cps[] = new ProgressContributor[tasks.size()];
int i = 0;
//tasks.get(1).
for (AbstractTask task : tasks) {
cps[i] = task.getProgressContributor();
i++;
}
AggregateProgressHandle aph =
AggregateProgressFactory.createHandle(
"MyTasks", // displayed name
cps, // progress contributors
null, // not cancelable
null); // no output
aph.start();
for (AbstractTask task : tasks) {
task.start();
}
}
}
any hints on how it constructed appeciated ...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
golan2
Offline
Joined: 2011-02-02

Hi,
Are you talking about the "for-each" loop?
It iterates all the elements in the collection.
See: http://download.oracle.com/javase/1.5.0/docs/guide/language/foreach.html
Best regards,
Izik Golan
golan2@hotmail.com