集册 Java实例教程 列出班级测验

列出班级测验

欢马劈雪     最近更新时间:2020-01-02 10:19:05

452
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
  • 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 (
展开阅读全文