首页 > 代码库 > http://wsfly.iteye.com/blog/1152248
http://wsfly.iteye.com/blog/1152248
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。