13,100
社区成员
发帖
与我相关
我的任务
分享
String a[]={"还","爱","哈","唉","啦","爱","拿","还","哈"};
Vector vc = new Vector();
boolean c = true;
vc.addElement(a[0]);
for(int i = 1; i < a.length; i++){
c = true;
for(int j = 0; j < vc.size(); j++){
if(vc.elementAt(j) == a[i]){
c = false;
}
}
if(c){
vc.addElement(a[i]);
}
}
a = new String[vc.size()];
for(int i = 0; i < a.length; i++){
a[i] = String.valueOf(vc.elementAt(i));
System.out.println(a[i]);
}
Hashtable table = new Hashtable();
int cou = 0;
for(int i = 0; i < a.length; i++){
System.out.print(a[i]);
if(table.containsKey(a[i])){
cou++;
}else{
table.put(a[i],new Integer(i-cou));
}
}
a = new String[table.size()];
Enumeration e = table.keys();
while(e.hasMoreElements()){
String str = (String)e.nextElement();
int index = ((Integer)table.get(str)).intValue();
a[index] = str;
}
String a[]={"还","爱","哈","唉","啦","爱","拿","还","哈"}
List<String> list = Arrays.asList(a);
Set<String> set = new HashSet<String>(list);
System.out.print("Remove duplicate result: ");
//Create an array to convert the Set back to array. The Set.toArray()
// method copy the value in the set to the defined array.
String[] result = new String[set.size()];
set.toArray(result);
for (String s : result) {
System.out.print(s + ", ");
}