Re: Sorting a vector based on another datas



zelao.itu@xxxxxxxxx <zelao.itu@xxxxxxxxx> wrote:
Could I insert these values in a Map Collection and then sort it by
any term that I choose

Yes, but you can also sort the Vector elements directly
(without shuffling around between various collection types)
by implementing your specific Comparator derived class, which
implements compare(x,y) according to the order you have in mind,
and passing an instance of your Comparator to Collections'
sort(List<T> list, Comparator<? super T> c) method.
(yes, a Vector is also a List)

.



Relevant Pages

  • Re: Sorting objects in ooRex? is this possible with data structures?
    ... The sorting features are modeled off of what Java does with its Comparable and Comparator classes. ... If you want to sort on different column positions, we have a Comparator class that allows you to specify the comparison colums. ... Here's one that compares strings as numbers: ...
    (comp.lang.rexx)
  • comparator
    ... I am testing a Comparator with the PriorityQueue, ... added the number 100 or 1000 to the list, it did not sort right. ... public class NumberAscComparator implements Comparator ...
    (comp.lang.java.programmer)
  • Re: indirect sort
    ... puts it into an array and sorts this array is faster than ... just sorting the objects. ... worthy to have my own implementation of sort(), ... comparator can simple subtract one argument from the other and cast ...
    (comp.lang.java.programmer)
  • Re: indirect sort
    ... I wrote a Comparator (I don't want to use ... Comparable in order to be able to choose the field I am sorting by) ... a way to create a doublearray of my fields I want to sort by, ...
    (comp.lang.java.programmer)
  • Re: implementing comparable
    ... they want to sort on. ... basically you need a vector of vectors, not a vector of strings. ... COPY THE DATA TO A LOCAL ARRAY OF THE RIGHT SIZE ... Basically i was fumbling about in the comparator, ...
    (comp.lang.java.programmer)