一个Java程序 求步骤意义
package delete;import java.util.ArrayList;
import java.util.List;
public class deleteaa {
public static void main(String [] args) {
testA();
System.out.println("");}
public static void testA() {
String [] str = {"1", "2", "6", "2", "6", "7", "1"};
for (String elementA:str ) {
System.out.print(elementA + " ");
}
List<String> list = new ArrayList<String>();
for (int i=0; i<str.length; i++) {
if(!list.contains(str[i])) {
list.add(str[i]);
}
}
/*
Set<String> set = new HashSet<String>();
for (int i=0; i<str.length; i++) {
set.add(str[i]);
}
String[] newStr = set.toArray(new String[1]);
*/
System.out.println();
String[] newStr = list.toArray(new String[1]); //返回一个包含所有对象的指定类型的数组
for (String elementB:newStr ) {
System.out.print(elementB + " ");
}
System.out.println();
}
}
谁能帮忙详细说明下各个步骤