class StrLenCompare implements Comparator<String>
{
public int compare(String s1,String s2)
{
if (s1.length()>s2.length())//在这里s1与s2都是String类型的,String类型调用长度方法不应该是s1.length吗,怎么这个地方加上了()
{
return 1;
}
else if (s1.length()<s2.length())
{
return -1
}
else
return s1.compareTo(s2);
}
}
|
|