-1

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);
    }
}
4
  • What online compiler? what version of java? Commented Nov 28, 2021 at 4:47
  • Does this Q&A resolve your problem? stackoverflow.com/questions/45743779 Commented Nov 28, 2021 at 6: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) Commented Dec 2, 2021 at 20:26
  • I know this is a duplicate, but it helped me find the correct answer since its title was exactly describing my problem, so thanks for that! =^,^= Commented Nov 5, 2024 at 13:11

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.