It's not a secret anymore!
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: 484

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: 20057
    
  44


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: 484

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: 44013
    
  33
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: 44013
    
  33
Sorry, I hadn't realised Henry had already replied.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44013
    
  33
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: What does this statement mean: for (Device device : deviceCollection.getDevices())
 
It's not a secret anymore!