File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes for each loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "for each loop" Watch "for each loop" New topic

for each loop

akash shrimali
Ranch Hand

Joined: Jul 28, 2010
Posts: 45
how can we perform ternary operation in new enhanced FOR EACH LOOP [ EX ... for(int element:arr) { System.out.println(element); } ]
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Your example does not have a ternary operation and it is not obvious to me what is not obvious to you. Can you elaborate?

Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Hi Akash,

it doesn't seem so clear to me what you want to achieve.

Following your example:

Would you like to give to element variable a value depending on a condition? If that is the question, no is the answer

But you can choose the array or list to navigate through, depending on a conditional operator's result

Tell me if you meant something else.

I agree. Here's the link:
subject: for each loop
It's not a secret anymore!