Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to begin the enhanced for loop from the end in java [duplicate]

Tags:

java

for-loop

I have two lists in Java. For one, i want to iterate from the beginning and for the other I want to start from the end. I wanted to use enhanced for loop for this, but i am unsure how to do that. Any suggestions?

like image 958
Vikram Avatar asked Dec 20 '22 03:12

Vikram


1 Answers

No, you cannot use the Enhanced For-Loop to iterate from the end to the beginning of a List. Enhanced For-Loops should be used for simplicity when you wish to step through the elements in a first-to-last order. In any other cases, the "standard" For-Loop is the most optimal.

like image 136
AngelTrs Avatar answered May 05 '23 11:05

AngelTrs