I've been trying to figure out a way to print out values for an enhanced for loop statement for awhile now and just can't quite seem to figure out how to do it. I understand the basic concepts of an enhanced for loop but I can't seem to figure out how to use it in my scenario.
Here is the code:
import java.util.ArrayList;
public class userGroup {
ArrayList<User> userGroup = new ArrayList<>();
User user0;
public void addSampleData() {
userGroup.add(user0);
}
public void printusername(){
for (User x: userGroup)
System.out.println(x);
}
}
How would I implement a for loop statement in the printusername method that prints out user0 and its values? I understand that it's probably because there is an error somewhere in the creation of the ArrayList but I just can't find out where the error(s) are. Any help would be greatly appreciated by me and anybody else who may have the same issue. Thanks.