转自:
http://www.cnblogs.com/bluedream2009/archive/2009/10/26/1590285.html
Set集合会将重复的键值过滤掉.利用这一特性.可以将数组里相同的字符串过滤掉.
public static void main(String[] args) {
String[] str = {"a", "b", "c", "b", "c", "d","a"};
Set<String> set = new HashSet<String>();
// 将Collection追加到Set中
set.addAll(Arrays.asList(str));
// 将Set转储到一个新分配的数组
String[] result = set.toArray(new String[0]);
for(String str2: result){
System.out.print("==>" + str2);
}
}
结果:
==>d==>a==>c==>b