sort keyword array in loop

I need to be able to sort my keyword array by label sometimes and by value others.

I first create the array from a keword item:

#set($keywordChoices = $rx.keyword.keywordChoices($keyword_filter))##

Then I loop:

#foreach($choice in $keywordChoices)##

But I would LIKE to do (not sure of how to sort by Value or Label but maybe something like):

#foreach($choice in $tools.sorter.sort($keywordChoices, “Value”))##

Is there a simple way to do this?

Thanks

Possible Solution

#set($keywordChoices = $rx.keyword.keywordChoices('keywordSet'))##
#set($sort = [])##
#foreach($choice in $keywordChoices)##
#set($sortItem = {})##
#set($sortItem.name = $choice.get(0))##
#set($sortItem.value = $choice.get(1))##
#if($sort.add($sortItem))##
#end##
#end##
#foreach($sortItem in $tools.sorter.sort($sort,"name:desc"))##
$sortItem.name.toString()
$sortItem.value.toString()
#end##

Explanation:
[ol]
[li]Set our keywordChoices ($keywordChoices)[/li][li]Set up a list ($sort)[/li][li]Iterate through the ArrayList ($keywordChoices)[/li][li]Set up a map object ($sortItem)[/li][li]Set up name and value properties ($sortItem.name $sortItem.value)[/li][li]Add map object to list ($sort.add($sortItem))[/li][li]Iterate through $tools.sorter.sort($sort,“name:desc”)[/li][li]Access properties through $sortItem.name.toString()[/li][/ol]

This could be a Java Extension to save time. I’m also looking for a better process.