0

I was creating an ArrayList, and i am getting following error Exception in thread "main" java.lang.Error: Unresolved compilation problem: ArrayList cannot be resolved to a type Please help.

package learnCoreJava;

import java.util.List;

public class ArrayListDemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // Always initialize the concrete implementation with the interface types
                List<Integer> arrayList = new ArrayList<>(5);
                
                for(int i=0;i<=5;i++)
                    arrayList.add(i);
                
                System.out.println(arrayList);
    }

}
2
  • 3
    You have to import java.util.ArrayList as well. Commented Feb 9, 2022 at 9:05
  • 3
    If you are using an IDE like eclipse or intellij, you should check your IDE's suggestions. Surely there are wiggly lines near the ArrayList. Commented Feb 9, 2022 at 9:11

1 Answer 1

2

Add this import statement :-

import java.util.ArrayList;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.