public int compareTo ( Account o ) { if ( this . isFolder ( ) && ! o . isFolder ( ) ) return - 1 ; else if ( ! this . isFolder ( ) && o . isFolder ( ) ) return 1 ; // First ignore case, if they equate, use case. int result = name . compareToIgnoreCase ( o . name ) ; if ( result == 0 ) return name . compareTo ( o . name ) ; else return result ; }
Implements the Comparable&lt ; Account&gt ; interface this is based first on if the account is a folder or not . This is so that during sorting all folders are first in the list . Finally it is based on the name .