Weird for() statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zeny
    New Member
    • Jul 2006
    • 44

    #1

    Weird for() statement

    Hi everyone! Does anyone can explain the ":" in the for() statement below?

    Example:

    Integer[] integerArray = { 1, 2, 3, 4, 5};

    for ( Integer element : integerArray )
    System.out.prin tf( "%s ", element );

    Thanks for the attention.
  • PLA
    New Member
    • Aug 2006
    • 44

    #2
    Originally posted by zeny
    Hi everyone! Does anyone can explain the ":" in the for() statement below?

    Example:

    Integer[] integerArray = { 1, 2, 3, 4, 5};

    for ( Integer element : integerArray )
    System.out.prin tf( "%s ", element );

    Thanks for the attention.
    It's new in Java 5.0, you have the ability to write 'simple' for statement when you iterate over an array or a collection, ':' means 'in' , you should read your line

    for each integer element in integerArray do

    More info here

    Comment

    • zeny
      New Member
      • Jul 2006
      • 44

      #3
      Thanks for the explanation PLA, this is indeed a very cool new feature of Java 5.

      Java rules!

      Comment

      Working...