package listtest;
import java.util.ArrayList;
import java.util.List;
public class RepTest {
public static void main(String[] args) {
List myList = new ArrayList();
myList.add(0, "java");
myList.add(1, "c++");
myList.add(2, "html");
myList.add(3, "python");
myList.add(4, "js");
myList.add(5, "python");
myList.add(6, "go");
System.out.println(myList);
List list1 = new ArrayList();
for (int i = 0; i < myList.size(); i++) {
if (!list1.contains(myList.get(i))) {
list1.add(myList.get(i));
}
}
System.out.println(list1);
}
}
输出结果:
[java, c++, html, python, js, python, go]
[java, c++, html, python, js, go]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)