Android Question change order of list to reverse

tufanv

Expert
Licensed User
Longtime User
Hello,

I have a list in my app. Is there any way to change the sort of the list from the reverse , I mean if we have

4,7,5,8,1,2 in our list is it possible to make the list
2,1,8,5,7,4

Thanks
 

stevel05

Expert
Licensed User
Longtime User
As the items are not actually sorted the simplest way is to use another list and add the items in reverse order.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
.. or simply read it bottom-up..eheh
 
  • Like
Reactions: eps
Upvote 0

eps

Expert
Licensed User
Longtime User
@udg has the best idea.

It's a bit difficult to know how you're accessing your 'list' though.. Where it comes from and how it's populated as well..
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Upvote 0

sadeq.hitex

Member
Licensed User
The easiest way to reverse a list :

my list :
B4X:
Dim list1 As List = Array As Int(4,7,5,8,1,2)

use 'reverse' code :
B4X:
Dim java As JavaObject
java.InitializeStatic("java.util.Collections").RunMethod("reverse", Array(list1))

log to see the result :
B4X:
Log("list : " & list1)

The final result will be :
B4X:
list : (ArrayList) [2, 1, 8, 5, 7, 4]

...Note... :

You can use
B4X:
list1.Sort(True)
but in this case , the items must all be numbers or strings!
 
Last edited:
Upvote 0
Top