Why is my enhanced loop not working?
Vector<String> v = new Vector<String>();
v.add("one");
v.add("two");
v.add("three");
for(String str : v){
System.out.println(v);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem with you code is that in the for statement instead of this:
you should have this:
making the final code like this:
In simple terms you are giving the value of
vto a string calledstr, then you print it usingSystem.out.println(...)and this loop will continue until there are no more items left fromvto print.Hope it helps.