日期:2014-05-20 浏览次数:20738 次
import java.util.*; public class Test { public static void main(String[] args) { String fact = "EDUCATION SHOULD ESCHEW OBFUSCATION"; List<String> strings = Arrays.asList(fact.split("")); Iterator<String> iter = strings.iterator(); while(iter.hasNext()) { System.out.print(iter.next()+" "); } System.out.println(); PriorityQueue<String> stringPQ = new PriorityQueue<String>(strings); while(stringPQ.peek()!=null) { System.out.print(stringPQ.remove()+" "); } } }
fact.split(" ")
------解决方案--------------------
List<String> strings = Arrays.asList(fact.split(""));
PriorityQueue<String> stringPQ = new PriorityQueue<String>(strings);
你把List容器里的所有元素添加到PriorityQueue容器里了
看看你的PriorityQueue构造方法里添加了什么?-----"strings"(建议你查看下API文档)
并且PriorityQueue容器对元素进行了自然顺序的排序...
因此打印结果为:
A A B C C C D D E E E F H H I I L N N O O O O S S S T T U U U