Java ArrayList


#1

public class GeneralizationsD {
public static void main(String[] args) {

	for(String sport : sports) 
ArrayList<String> sports= new ArrayList<String>();

The code comes out with an error.

GeneralizationsD.java:10: error: variable declaration not allowed here
ArrayList sports= new ArrayList();
^
1 error


#2

The declaration should be at a point before the loop, not inside it.


#3

Thank you very much! :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.