Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.PriorityQueue; public class Main { public static List<String> getSortedStringList(Collection<String> toSort) { List<String> sorted = new LinkedList<String>(); final PriorityQueue<String> ordered = new PriorityQueue<String>( toSort.size() + 1/*In case the toSort is empty*/, new Comparator<String>() { @Override public int compare(String lhs, String rhs) { lhs = lhs.replaceAll("[^a-zA-Z0-9]", ""); rhs = rhs.replaceAll("[^a-zA-Z0-9]", ""); int result = rhs.compareTo(lhs); return result; } }); ordered.addAll(toSort); int originalSize = ordered.size(); for (int i = 0; i < originalSize; i++) { sorted.add(ordered.poll()); } return sorted; } }