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: 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)
  • Re: Can you help me understand this?
    ... My question is not related to ananymous class concept, ... The sort method would use the specified comparator in order to figure out the ordering of the sort. ... So when you're writing your own comparator, you need to implement the compare method in such a way that if you are handed two arbitrary members "o1" and "o2" from the list, your method returns the correct result as apecified in the documentation of the Comparator interface - i.e return a negative number if o1 should appear before o2 in the ordering, a positive number if o1 should come after o2, and zero if the two objects are deemed to be equal. ...
    (comp.lang.java.programmer)
  • Re: "Sorting" assignment
    ... Which would seem to imply that sort should be taught ... sorting is where many object-oriented languages fall down. ... Sorting really IS "matching all members of an array against, ... C's qsortinterface means that all is required is a custom comparator ...
    (comp.programming)