-1

hello i'm trying ton understand a programm and a line giving me some trouble. Can you explain me the Construction of this line because i have never seen a "For" like that

for (Iterator<IBaseVO> itMachine = machinesSelected.iterator(); itMachine.hasNext();) {
            MachineVO mach = (MachineVO) itMachine.next();
            idsMachines.add(mach.getMchId());
        }

thanks you

kazor02x
  • 43
  • 2
  • 8

1 Answers1

1

A for loop can have 3 arguments, but it's not required.

Usually goes like this

  1. instruction
  2. boolean
  3. instruction

the first and the third one can be omitted safely.

So here is the first instruction slot used to initialize the iterator object.

The second instruction slot is used to see if there are new items in the iterator.

the third slot is not needed and thusly omitted.

This does the same as

Iterator<IBaseVO> itMachine = machinesSelected.iterator();
while (itMachine.hasNext()) {
            MachineVO mach = (MachineVO) itMachine.next();
            idsMachines.add(mach.getMchId());
        }
Tschallacka
  • 27,901
  • 14
  • 88
  • 133