I have taken this example from net . But when i tried it is not compiling saying cannot convert Object to String
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList names = new ArrayList();
names.add("Amy");
names.add("Bob");
names.add("Chris");
names.add("Deb");
names.add("Elaine");
names.add("Frank");
names.add("Gail");
names.add("Hal");
for (String nm : names)
System.out.println((String)nm);
}
}
If it is a normal for loop i could have done list.get(element index).toString() . but how to do in enhanced for loop ??