提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
- Create instance of java.util.List
- Add value to it with a for loop
- Use for each loop to output values in the List.
import java.util.ArrayList; import java.util.List; /*时 代 J a v a 公 众 号 - nowjava.com*/ public class Main { public static void main(String[] arguments) { List<String> list = new ArrayList<>(); String[] codes = { "alpha", "lambda", "gamma", "delta", "zeta" }; for (int i = 0; i < codes.length; i++) { if (!list.contains(codes[i])) { list.add(codes[i]); } } // display all codes