Java Java Data Structures Organizing Data Interfaces

A little explanation

Please I need a little explanation on this code written at the Example.java class: for (Treet exampleTreet : treets) { System.out.println(exampleTreet); }

Try watching the arrays series of videos for java.

1 Answer

Mark Casavantes
PRO
Mark Casavantes
Pro Student 13,401 Points

Good Morning Eugene,

Basically, there is more than one way to create a for loop. What is listed below is what you may be most familiar with.

for (initialization condition; testing condition; increment/decrement)
{
    statement(s)
}

There is also this way of creating a for loop which relates to the example you provided.

int [] numbers = {10, 20, 30, 40, 50};

for(int x : numbers ) 
{
         System.out.print( x );
         System.out.print(", ");
}

Mark