提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
- Declare a List
- Add String value to it if it is not yet being added.
- Use Iterator to loop through the List
/* 来自 NowJava.com - 时 代 Java*/ import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static void main(String[] arguments) { List<String> list; String[] codes = { "alpha", "lambda", "gamma", "delta", "zeta" }; list = new ArrayList<>(); for (int i = 0; i < codes.length; i++) { if (!list.contains(codes[i])) { list.add(codes[i]); } } for (