Hi I am (very) new to java and I come from a c++ background and I am getting this error:
Array-Lists-In-java.java:3: error: '{' expected
public class Array-Lists-In-java{
^
and here is my code:
import java.util.ArrayList;
public class Array-Lists-In-java {
public static void main(String[] args)
{
ArrayList<String> grocery = {"Onions","Carrots","Olives", "olive oil"};
printArray(grocery);
grocery.add("Tomatoes");
printArray(grocery);
}
public static void printArray(ArrayList<String> list)
{
for(int i = 0; i < list.size(); i++)
{
System.out.println(list.get(i));
}
}
}
what am I doing wrong??pls correct me where i am going wrong it would be really helpful
thanks