aspose file tools*
The moose likes Beginning Java and the fly likes What does this statement mean: for (Device device : deviceCollection.getDevices()) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What does this statement mean: for (Device device : deviceCollection.getDevices())" Watch "What does this statement mean: for (Device device : deviceCollection.getDevices())" New topic
Author

What does this statement mean: for (Device device : deviceCollection.getDevices())

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Im getting some help from someone with a problem I have, but Im unsure what the : operator is. Ive looked online and all I can find are examples of a ? : operator, but no : by themselves.

So can someone attempt to tell me what that statement mean? for (Device device : deviceCollection.getDevices())

Im sure its something like, for every device in the Device class, perform getDevices from the deviceColelction class

That is probably not completely correct though


True wisdom is in knowing you know nothing - Socrates
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18829
    
  40


http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Seems pretty starightforward, if Im corect it is pretty much saying for each device in the device collection { do this } right?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
It is a for-each loop, which was introduced to Java with Java5, also called an enhanced for loop. It is in fact the same construct as described in this Java™ Tutorials section. Obviously the getDevices method returns a Device[] array.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
Sorry, I hadn't realised Henry had already replied.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
Matt Kohanek wrote:Seems pretty starightforward, if Im corect it is pretty much saying for each device in the device collection { do this } right?
Yes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does this statement mean: for (Device device : deviceCollection.getDevices())