Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reversing the Items In a Collection

What is the easiest way to reverse the items in a VBA collection?

like image 538
Dan Avatar asked Nov 17 '10 10:11

Dan


People also ask

How do you reverse a collection element?

reverse() method of Collections class as the name itself suggests is used for reversing elements been there up in the object in which they are stored. It reverses the order of elements in a list passed as an argument. Parameter: Object of a class whose elements are to be reversed.

What is collection reverse?

The reverse function of the Collections class is used to reverse the order of elements in a specified list. Collections is defined in the util package in Java, so you must import the util package before you can use the reverse function, as shown below. import java. util.

How do I reverse print collection order?

The reverseOrder() method of Collections class that in itself is present inside java. util package returns a comparator and using this comparator we can order the Collection in reverse order.

How do you reverse a list in slicing?

Now, when it comes to using slicing for reversing a list, you would need to use the reverse slicing operator [::-1] syntax. This sets the step to -1 and gets all items in the list in reverse order. The slicing operator does not modify the original list.


1 Answers

Don't know of any neat way of doing it but you could do something like (code not tested):

Dim MyNewCol as New Collection
For Each obj in MyCol
    If MyNewCol.Count > 0 Then
        MyNewCol.Add item := obj, before := 1
    Else
        MyNewCol.Add item := obj
    End If
Next
like image 147
Hans Olsson Avatar answered Sep 30 '22 08:09

Hans Olsson