There is a cycle:

for (Contact cn : contacts) 

What does the colon mean and how to write in the classical form?

    2 answers 2

    This is the classic type of foreach loop.

    There is a certain object being iterated (for example, an array or a collection) of contacts , in which elements are of type Contact (or can be brought to it). For each element, the body of the loop is executed, in which it has the name cn .

    • more precisely, some entities that implement the interface Iterable <T> - Nikita
    • @Nikita, thanks, corrected. - Qwertiy

    This is the so-called range-based loop. Classic equivalent:

     for (i = 0; i < contacts.size(); ++i) { Contact cn = contacts[i] ... } 
    • This code is valid only if contacts is an array. - Qwertiy
    • @Qwertiy, in fact it is not true, be contacts array or list. If the array is, then its length is ARRAY.lenght , if the List , then you need to get the element through LIST.get(i) . Neither there nor here it turns out) - YuriySPb
    • one
      @ YuriySPb, yes, I thought about get, but forgot about length))) - Qwertiy
    • Thanks to all! I understood the meaning and already use it. - kaaa