public static void sortFile ( List < File > jarsList , final String fName ) { Collections . sort ( jarsList , new Comparator < File > ( ) { @ Override public int compare ( File f1 , File f2 ) { String f1Name = f1 . getName ( ) ; f1Name = f1Name . substring ( fName . length ( ) + 1 , f1Name . length ( ) - 4 ) ; String f2Name = f2 . getName ( ) ; f2Name = f2Name . substring ( fName . length ( ) + 1 , f2Name . length ( ) - 4 ) ; Version v1 = Version . createVersion ( f1Name ) ; Version v2 = Version . createVersion ( f2Name ) ; if ( v1 != null && v2 != null ) return v1 . compareTo ( v2 ) ; return f1Name . compareTo ( f2Name ) ; } } ) ; }
Compare files in jarsList based on file name s length Sort the files depending on the comparison