我有两个列表,一个字符,另一个列表freq。我想根据freq排序字符。使用来自另一个列表的比较对列表进行排序
我做://我用c在这里,而不是性格
Collections.sort(c,new Comparator()
{
public int compare(Character c1, Character c2)
{
return (Comparable)freq.get(c.indexOf(c1)).compareTo(freq.get(c.indexOf(c2)));
}
});
但代码给出了一个错误。
chef_code.java:33: error: <anonymous chef_code$1> is not abstract and does not override abstract method compare(Object,Object) in Comparator
{
^
chef_code.java:36: error: local variable c is accessed from within inner class; needs to be declared final
return (Comparable)freq.get(c.indexOf(c1)).compareTo(freq.get(c.indexOf(c2)));
^
chef_code.java:36: error: local variable freq is accessed from within inner class; needs to be declared final
return (Comparable)freq.get(c.indexOf(c1)).compareTo(freq.get(c.indexOf(c2)));
^
chef_code.java:36: error: local variable c is accessed from within inner class; needs to be declared final
return (Comparable)freq.get(c.indexOf(c1)).compareTo(freq.get(c.indexOf(c2)));
^
chef_code.java:36: error: local variable freq is accessed from within inner class; needs to be declared final
return (Comparable)freq.get(c.indexOf(c1)).compareTo(freq.get(c.indexOf(c2)));
^
chef_code.java:36: error: incompatible types
return (Comparable)freq.get(c.indexOf(c1)).compareTo(freq.get(c.indexOf(c2)));
^
required: int
found: Comparable
请帮忙。
是什么',其他freq'?什么“不工作”? –
“给出错误”..什么错误? – Mik378
你应该提供更多的代码。单单这个片段不能给我们足够的案例/问题的看法。 – arjacsoh