Search code examples
blackberryblackberry-jde

Sorting an array of String in BlackBerry


I need to sort an array of String like the following, in ascending order.

String str[] = {"ASE", "LSM", "BSE", "LKCSE", "DFM"};

How to do that? I need help.


Solution

  • This answer is based on Signare and HeartBeat's suggestion. Explore this link for details. Also this link, Sorting using java.util.Array might be helpful.

    // Initialization of String array 
    String strs[] = {"One", "Two", "Threee", "Four", "Five", "Six", "Seven"};
    
    // implementation of Comparator
    Comparator strComparator = new Comparator() {
        public int compare(Object o1, Object o2) {
            return o1.toString().compareTo(o2.toString());
        }
    };
    
    // Sort
    Arrays.sort(strs, strComparator);