fork download
import java.util.*;
import java.util.regex.*;

public class Main { 
    public static class TrendListComparator implements Comparator {
         // retrieve the P and S
         final Matcher m = Pattern.compile(".*_S(\\d+)_P(\\d+).*_S(\\d+)_P(\\d+).*").matcher("");
         public int compare(String str1, String str2) {
             if (m.reset(str1 + str2).matches()) {
                 Integer s1 = Integer.valueOf(m.group(1));
                 Integer p1 = Integer.valueOf(m.group(2));
                 Integer s2 = Integer.valueOf(m.group(3));
                 Integer p2 = Integer.valueOf(m.group(4));
                 // compare
                 return s1.equals(s2) ? p1.compareTo(p2) : s1.compareTo(s2);
             } else {
                 return str1.compareTo(str2); // standard sort if no P and S
             }
         }
    }
    
   public static void main(String[] args) {
        List trendList = Arrays.asList(("ACLK_SCRN_200MHZ_DATAB_S0_P0:8 \n" +
            "ACLK_SCRN_200MHZ_DATAB_S0_P10:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P11:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P12:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P13:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P14:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P15:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P1:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P2:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P3:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P4:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P5:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P6:8 \n" +
            "MLC_C_SAMPLE\n" +
            "MLC_SAMPLE\n" +
            "SWR\n" +
            "TOUCHDOWN\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P7:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P8:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S0_P9:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P0:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P10:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P11:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P12:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P13:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P14:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P15:8\n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P1:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P2:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P3:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P4:8 \n" +
        	"ACLK_SCRN_200MHZ_DATAB_S1_P5:8 \n" +
        	"TEST_REV").split("\n")
        );
        
        Collections.sort(trendList, new TrendListComparator());
        for (String trend: trendList)
            System.out.println(trend);
   }
}
Success #stdin #stdout 0.09s 380160KB
stdin
Standard input is empty
stdout
ACLK_SCRN_200MHZ_DATAB_S0_P0:8 
ACLK_SCRN_200MHZ_DATAB_S0_P1:8 
ACLK_SCRN_200MHZ_DATAB_S0_P2:8 
ACLK_SCRN_200MHZ_DATAB_S0_P3:8 
ACLK_SCRN_200MHZ_DATAB_S0_P4:8 
ACLK_SCRN_200MHZ_DATAB_S0_P5:8 
ACLK_SCRN_200MHZ_DATAB_S0_P6:8 
ACLK_SCRN_200MHZ_DATAB_S0_P7:8 
ACLK_SCRN_200MHZ_DATAB_S0_P8:8 
ACLK_SCRN_200MHZ_DATAB_S0_P9:8 
ACLK_SCRN_200MHZ_DATAB_S0_P10:8
ACLK_SCRN_200MHZ_DATAB_S0_P11:8
ACLK_SCRN_200MHZ_DATAB_S0_P12:8
ACLK_SCRN_200MHZ_DATAB_S0_P13:8
ACLK_SCRN_200MHZ_DATAB_S0_P14:8
ACLK_SCRN_200MHZ_DATAB_S0_P15:8
ACLK_SCRN_200MHZ_DATAB_S1_P0:8 
ACLK_SCRN_200MHZ_DATAB_S1_P1:8 
ACLK_SCRN_200MHZ_DATAB_S1_P2:8 
ACLK_SCRN_200MHZ_DATAB_S1_P3:8 
ACLK_SCRN_200MHZ_DATAB_S1_P4:8 
ACLK_SCRN_200MHZ_DATAB_S1_P5:8 
ACLK_SCRN_200MHZ_DATAB_S1_P10:8
ACLK_SCRN_200MHZ_DATAB_S1_P11:8
ACLK_SCRN_200MHZ_DATAB_S1_P12:8
ACLK_SCRN_200MHZ_DATAB_S1_P13:8
ACLK_SCRN_200MHZ_DATAB_S1_P14:8
ACLK_SCRN_200MHZ_DATAB_S1_P15:8
MLC_C_SAMPLE
MLC_SAMPLE
SWR
TEST_REV
TOUCHDOWN