• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems pretty starightforward, if Im corect it is pretty much saying for each device in the device collection { do this } right?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I hadn't realised Henry had already replied.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic