tags:

views:

66

answers:

1

012@TEST1 524@TEST2 ABC@TEST3 AB@TEST4 53@TEST5 @TEST6

i want to sort the following data such that Final output: Sorted on the basis of data before ‘@’ Numbers should come before alpha

@TEST6 012@TEST1 53@TEST5 524@TEST2 AB@TEST4 ABC@TEST3

i want to implement this in java ...help me out

+3  A: 
List<String> stringList = Arrays.asList(new String[]{"012@TEST1", "524@TEST2","ABC@TEST3" ,"AB@TEST4" ,"53@TEST5","@TEST6"});

    Collections.sort(stringList,new Comparator<String>(){

        public int compare(String s1,String s2){  
            String c1,c2;
            if (s1.split("@").length >1){c1 = s1.split("@")[0]}else{c1 = ""}
            if (s2.split("@").length >1){c2 = s2.split("@")[0]}else{c2 = ""}
            return c1.compare(c2);
        }
});

Or something like that, just tweak the compare method

Khanser
i am not aable to understand the code please can anyone give some other way out or help me understand the code ..thanks
abhinav singh
Are you looking for a pseudo-code algorithm or an implementation in a specific language (possibly using libraries provided by that platform)?This example looks like Java using a sort routine from the platform libraries.
bunn_online
My example is written in Java isn't what you needed?
Khanser