要对ArrayList集合进行排序,主要使用Collections中的sort方法,具体如下:
下面按照集合中的字符长度排序:
collections.sort(list,new Comparator()
{
public int Compare(Object o1,Object o2)
{
String one = o1.toString();
String two = o2.toString();
if (one.length > two.length)
{
return 1;
}
else (one.length = two.length)
{
return 0;
}
return -1;
}
}
)
下面按照集合中的字符长度排序:
collections.sort(list,new Comparator()
{
public int Compare(Object o1,Object o2)
{
String one = o1.toString();
String two = o2.toString();
if (one.length > two.length)
{
return 1;
}
else (one.length = two.length)
{
return 0;
}
return -1;
}
}
)