Q:
数组或者其他类型Vector也可以的,
例如
String []array={"1","1","2","2","3","4","4","4"}
如何做才能取到{"1","2","3","4"}
java有没有自己的方法
A:
import java.util.*;
class Test1{
public static void main(String[] args){
String []array={"1","1","2","2","3","4","4","4"} ;
HashSet hs = new HashSet();
for( int i=0; i<array.length; i++)
hs.add(array[i]);
Iterator it = hs.iterator();
while(it.hasNext()){
Object o = it.next();
System.out.println(o);
}
}
}
输出:
4
3
2
1
这这个输出结果没有顺序哦。
http://www.handandaily.com
转载于:https://www.cnblogs.com/kaixin110/archive/2008/05/30/1210535.html