**
**
例如:
str = “1,23,2,3,45,56,18,34,78”;
结果:1,2,3,18,23,34,45,56,78
package util;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
//将字符串从大到小按顺序排序:
public class Test {
public static void main(String[]args){
try {
String str = "1,23,2,3,45,56,18,34,78";
HashSet set = new HashSet();//set 去重
for (int i = 0; i < str.split(",").length; i++) {
set.add(Integer.parseInt(str.split(",")[i]));
}
List list = new ArrayList();
list.addAll(set);
Collections.sort(list);//排序
System.out.println(list); //[1, 2, 3, 18, 23, 34, 45, 56, 78]
String liset1 = ""+list;
System.out.println(liset1); //[1, 2, 3, 18, 23, 34, 45, 56, 78]
String list3 = StringUtils.join(list,",");
System.out.println("liset3:"+list3); //1,2,3,18,23,34,45,56,78
boolean list4 = list3.equals("1,2,3,18,23,34,45,56,78");
System.out.println("list4:"+list4); //true
} catch (Exception e) {
e.printStackTrace();
}
}
}