private String[] names = { "bobby", "jones", "james", "george", "cletus", "don", "joey" };
public String getName() {
Random random = new Random();
String name = "";
int num = random.nextInt(names.length-1);
name = names[num];
names[num] = null; //HOW TO REMOVE FROM THE LIST???
return name;
}
I cannot remember how to remove the item from the list, please help.
This was my solution, thank everyone very much!
private String[] names = { "bobby", "jones", "james", "george", "cletus", "don", "joey" };
ArrayList<String> list = new ArrayList<String>(Arrays.asList(names));
public String getName() {
Random random = new Random();
String name = "";
int num = random.nextInt(names.length - 1);
name = list.get(num);
list.remove(num);
return name;
}