Mostrando postagens com marcador java. Mostrar todas as postagens
Mostrando postagens com marcador java. Mostrar todas as postagens

segunda-feira, 19 de setembro de 2016

Reverse a List in 3 different ways using Java

Hello!

From time by time you have to reverse a list and always have to remember how to do that...
So here are three different ways of doing that.

1) Recursive way;

2) Non-recursive way;

3) Simple way;

Here is the java code for your testing in my GitHub:

Click here to see the code in GitHub

Outputs:

########## REVERSE LIST ##########

Initial order list 1: [A, B, C, D, E, F]
==> 1) Reversed recursively
Reverse order list 1: [F, E, D, C, B, A]

Initial order list 2: [A, B, C, D, E, F]
==> 2) Reversed non-recursively
Reverse order list 2: [F, E, D, C, B, A]

Initial order list 3: [A, B, C, D, E, F]
==> 3) Reversed in a simple way using Collections.reverse
Reverse order list 3: [F, E, D, C, B, A]

########## END OF TEST ##########


I hope it helps you!
Please leave your comments or ideas!
See you!