String tests[] = {
"aaaa", "bbbb", "aaaa"
};
Analysis < String > an = new Analysis < String > (tests);
//an.add("aaaa");
//an.add("bbbb");
//an.add(111);
System.out.println(an.isOnlyOne());
/** *//**
*处理重复数
*/
class Analysis < T > {
private Set < T > temp = new HashSet < T > ();
private int count = 0;
public Analysis(){
}
public Analysis(T t){
temp = new HashSet < T > (Arrays.asList(t));
count = t.length;
}
/** *//**
*添加数据
*/
public void add(T t){
temp.add(t);
count++;
}
/** *//**
*检查是否有重复值
*/
public boolean isOnlyOne(){
//容器的实际大小
int containerSize = temp.size();
return count == containerSize;
}
}