This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

New syntax "Object o:c", Java 5.0  RSS feed

 
Ramu Ramaiah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a beginner to Java programming language. I am trying to learn the new "generics" functionality added to Java 5.0.

I came accross this peice of code from http://java.sun.com/developer/technicalArticles/J2SE/generics/

void printCollection(Collection<?> c) {
for(Object o:c) {
System.out.println(o);
}
}

I did not understand the syntax "Object o:c".
Can somebody explain what this means?

Thanks,
Ramu
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is nothing to do with generics. It's the new 'for each' loop. See the 'Iterating over Collections and Arrays with Enhanced for' section of the link.
 
Ramu Ramaiah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joanne.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!