-2

I am trying to run this java program in vscode but it shows an error on the 2nd line (The import java.util.ArrayList cannot be resolved Java(268435846)) and 6th line. But it gives correct output in an online compiler. Any suggestions?

import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
public class CollectionDemo {
    public static void main(String[] args) {
        ArrayList al = new ArrayList();
        al.add(100);
        al.add("String");
        System.out.println(al);
    }
}
  • What online compiler? what version of `java`? – Urmzd Nov 28 '21 at 04:47
  • Does this Q&A resolve your problem? https://stackoverflow.com/questions/45743779 – Stephen C Nov 28 '21 at 06:44
  • Agree with the other commentators: the version of Java (and other factors, like the host operating system) would be of benefit here. The output from the following commands might help get started: $ java -version $ javac -version (The '$' represent a command prompt - no need to type them) – monojohnny Dec 02 '21 at 20:26

1 Answers1

-1

The problem might be Java hasn't been configured correctly in VScode.Try running the program from the command prompt using java commands. If the code shows error running from the command line then the problem in java installation to your laptop.

sai manoj
  • 72
  • 3