I'm learning Java and I'm stuck with a little problem. The method .add() applied to my ArrayList object doesn't want to compile. I tried the same thing (with different parameters) on another program and it is working fine, so there's clearly something I've done wrong this time, but I can't figure out what. Any help would be appreciated.
import java.util.List;
import java.util.ArrayList;
private List<String> science = new ArrayList<String>();
science.add("geography");
This bit of code gives me the following error:
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error, insert "SimpleName" to complete QualifiedName
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "Identifier (" to complete MethodHeaderName
This is the entire code of the program:
import java.util.ArrayList;
import java.util.List;
public class Facolta {
        private String nome;
        private int facilities, tipo;
        private List<String> science = new ArrayList<String>();
        private List<String> other = new ArrayList<String>();
        science.add("geography");
        public Facolta(String nome, int facilities, int tipo) {
            this.nome = nome;
            if (science.toString().contains(nome)) {
                this.tipo = 2;
            }
            else if (other.toString().contains(nome)) {
                this.tipo = 1;
            }
            this.facilities = facilities;
        }
        public String getNome() {
            return nome;
        }
        public void setNome(String nome) {
            this.nome = nome;
        }
        public void getFacilities() {
            if (tipo == 1)
                System.out.println("Lab number: " + facilities);
            else if (tipo == 2)
                System.out.println("Library number: " + facilities);
            else
                System.err.println("Facility not available.");
        }
        public void setFacilities(int facilities) {
            if (facilities < 3) this.facilities = facilities;
            else System.err.println("Facility not specified.");
        }
}
 
     
     
     
     
    