public static String SortStringUsingSort(String toSort, String sortBy) {
        final HashMap<Character, Integer> orderMap = new HashMap<Character, Integer>();
        int init = 1;
        for (char c : sortBy.toCharArray()) {
            orderMap.put(c, init++);
        }
        ArrayList<Character> ca = new ArrayList<Character>();
        for (char c : toSort.toCharArray()) {
            ca.add(c);
        }
        Collections.sort(ca, new Comparator<Character>() {
            @Override
            public int compare(Character c1, Character c2) {
                Integer c1Order = (orderMap.get(c1) != null) ? orderMap.get(c1) : Integer.MAX_VALUE;
                Integer c2Order = (orderMap.get(c2) != null) ? orderMap.get(c2) : Integer.MAX_VALUE;
                System.out.println(c1 + "-" + c2 + "=" + (c1Order - c2Order));
                
                return c1Order - c2Order;
            }

        });
        //String s = String.valueOf(ca);
        StringBuffer sb = new StringBuffer();
        for (Character cc : ca) {
            sb.append(cc);
        }
        //System.out.println("sorted string: " + sb);
        return sb.toString();
    }