import java.util.*;
class test5
{
public static void main(String[] args)
{
List<String> list=new ArrayList<String>();//(Collections.reverseOrder());
list.add("aa");
list.add("abb");
list.add("cc");
list.add("bbdd");
Collections.sort(list,new Com());
String max=Collections.max(list);
int index =Collections.binarySearch(list,"abb");
// Collections.fill(list,"pp");//把所有元素变成pp
Collections.replaceAll(list,"aaa","adfads");
Collections.reverse(list);
System.out.println(list);
}
}
class Com implements Comparator<String>
{
public int compare(String s1,String s2)
{
if(s2.length()<s1.length())
return 1;
else if(s2.length()>s1.length())
return -1;
else
return 0;
}
}
问题:这条语句为什么没能实现反转,Collections.replaceAll(list,"aaa","adfads");
|
|