• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does this code mean in java?  RSS feed

 
william chaple
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the " : "

I actually tries to find java signs, but it did not come up for some reason. I know what =, ==, !=, || means, but not : lol

thanks guys
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for "enhanced for loop".
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
 
Campbell Ritchie
Marshal
Posts: 56561
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I tell you that you read that as
For each int x in numbers
… does that help?

By the way: call your ints i j k rather than x y z.
 
william chaple
Ranch Hand
Posts: 135
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes! perfect thank you!! Something so simple was never taught to me =)
 
MarirS NasavinirS
Greenhorn
Posts: 1
Chrome Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you also tell me how enhanced for loops can help me make my code more efficient? and how are they better than traditional for loops?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's mostly syntax candy so you can write more succinct code. I doubt there is a significant difference in performance though, if any.
 
Liutauras Vilda
Sheriff
Posts: 4922
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MarirS NasavinirS wrote:can you also tell me how enhanced for loops can help me make my code more efficient? and how are they better than traditional for loops?

Hi,

You cannot state like that. They were created for purpose mainly to iterate through collections in a "nicer", "simpler" syntax. And you're allowed basically to iterate only one way, > forward >.
Traditional "for" loop actually is more flexible.
 
Tim Holloway
Saloon Keeper
Posts: 18797
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicer, simpler, and more abstract. If "consistency is the hobgoblin of small minds", then Java was designed by giants. For iteration, we had array loops, while/next loops, and later Iterators.

The "for-each" construct replaces many of them and makes it easier to swap in and out different collection types without having to change the loop code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!