java - Order Set<Object> by attribute String -


i want sort set<tailledetail> 1 of string attributes (mesure), solutions saw in internet (treeset , comparator) don't work, can me?

my class:

public class tailledetail {     private integer id;     private string sexe;     private string mesure;     private taille taille; } 

edit -

for treeset try this:

set<tailledetail> tailles = new treeset<tailledetail>(); 

to remplace :

set<tailledetail> tailles = new hashset<tailledetail>(); 

and comparator try :

set<tailledetail> tailles = new hashset<tailledetail>(); comparator<tailledetail> comparatortaille = new comparator<tailledetail>() { @override public int compare(tailledetail left, tailledetail right) {     return left.tostring().comparetoignorecase(right.tostring());     } };  list<tailledetail> tai = tailledetailviewmanager.search(param, true);  collections.sort(tai, comparatortaille);  tailles = new hashset<tailledetail>(tai); 

the following code should make trick :

        final set tailledetails = new treeset(new tailledetailcomparator());                 tailledetails.add(...);          public class tailledetailcomparator implements comparator {                  @override                 public int compare(final tailledetail o1, final tailledetail o2) {                     return o1.mesure.compareto(o2.mesure);                 }             }  

note comparison going done using string comparison rules (alphabetically).


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -