标签:int contains new static sys font ring com []
public class Demo {
/**
* 去掉重复值
*/
public static void main(String[] args) {
String test = "100,120,166,1555,120,150,100";
String[] test1 = test.split(",");
ArrayList list = new ArrayList();
for (int i = 0; i < test1.length; i++) {
if (!list.contains(test1[i]))
list.add(test1[i]);
}
for (int i = 0; i < list.size(); i++)
System.out.println(list.get(i));
}
}
这个方法是很好,但是还有更加简单的
public class Demo {
/**
* 去掉重复值
*/
public static void main(String[] args) {
String test = "100,120,166,1555,120,150,100";
String[] test1 = test.split(",");
List list = Arrays.asList(test1);
Set set = new HashSet(list);
String [] rid=(String [])set.toArray(new String[0]);
for (int i = 0; i < rid.length; i++) {
System.out.println(rid[i]);
}
}
}
http://wsfly.iteye.com/blog/1152248
标签:int contains new static sys font ring com []
原文地址:http://www.cnblogs.com/winner-0715/p/6166025.html