How to add elements to List

Hi
I want to create an list and then pass that list to HierarchicalContainer

my code looks like this to create an list
import java.util.ArrayList;
import java.util.List;

import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.terminal.Resource;

public final class ExampleUtil {

  List<String> ls=new ArrayList<String>();
ls.add("1");

}

Am getting an error at this line ls.add(“1”); saying
Multiple markers at this line
- Syntax error on token(s), misplaced
construct(s)

Can anyone please let me know how to create an list in vaadin

This is not a Vaadin problem, but you are using Java in the wrong way. Classes can have fields in it directly, but all other code has to be put into methods, like the constructor. You are trying to add an item to the list outside a method.

This would work:

import java.util.ArrayList;
import java.util.List;

import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.terminal.Resource;

public final class ExampleUtil {

  public ExampleUtil(){
    List<String> ls=new ArrayList<String>();
    ls.add("1");
  }
}


Check here
for more info.