List sorting methods use the container

Today need to have saved to list container object in the array do the task when ordering, need to be sorted according to a property which was originally processed according to a bubble sort algorithm using the Internet search a bit later for a list of the container there are built-in methods when ordering. So to summarize this approach.

The Collections.sort (List, new new Comparator <class name stored in the List> () { 
              
            @Override 
            public  int Compare (class name t1, the class name T2) { 
                // attributes sorted in ascending order according to which, if desired descending words wherein of> to <to 
                IF (t1.get method name ())> t2.get method name ()) {
                     return . 1 ; 
                } 
                IF (t1.get method name ()) == t2.get method name () ) {
                     return 0 ; 
                } 
                return -1 ; 
            } 
        });

 

 

Guess you like

Origin www.cnblogs.com/1gaoyu/p/11885752.html