Java - general

sort vector (with Strings/Objects)

java.util.Vector
Example for a vector which only contains Strings:

Collections.sort(myVector, new Comparator<String>() {
   public int compare(String s1, String s2){
      return s1.compareTo(s2);
   }
});




Example for a vector which contains objects of the type MyClass:

Collections.sort(myVector, new Comparator<MyClass>() {
   public int compare(MyClass o1, MyClass o2){
      return o1.getsurname().compareTo(o2.getsurname());
   }
});
 
class MyClass{
   String strSurname;
   String strFirst name;
 
   public MyClass(String nachname, String vorname){
      strNachname = surname;
      strVorname = first name;
   }
 
   public String getSurname(){
      return strSurname;
   }
 
   public String getFirst name(){
      return strFirst name;
   }
}



Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007