JAVA simple ArrayList example

import java.util.*;

public class CodeKeeper {

ArrayList<String> list;
String[] codes = { “alpha”, “lambda”, “gamma”, “delta”, “zeta” };

public CodeKeeper(String[] userCodes) {

list = new ArrayList<>();
// load codes
for (int i = 0; i < codes.length; i++) {

if (!list.contains(code)) {

list.add(codes[i]);

}

}
// display all codes with new for loop
for (String code : list) {

System.out.println(code);

}

}

public static void main(String[] arguments) {

CodeKeeper keeper = new CodeKeeper(arguments);

}

}

Leave a Reply

You must be logged in to post a comment.