0

I am making a simple test code to add an element to an Arraylist in JAVA:

import java.util.ArrayList;

class MyArrayList 
{
    public static void main(String[] args)
    {
        ArrayList list = new ArrayList();
        list.add("Hello");
        System.out.println(list);
    }    
}

But it is returning this error:

MyArrayList.java:8: error: cannot find symbol
        ArrayList list = new Arraylist();
                             ^
  symbol:   class Arraylist
  location: class MyArrayList
Note: MyArrayList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Kriti
  • 23
  • 6
  • 1
    `Arraylist` should be `ArrayList` with a capital `L`. – John Kugelman Mar 01 '21 at 06:50
  • There are two separate problems. The "unresolved symbol" problem (see ^^^) and the "unchecked or unsafe operations" problem. Both are common problems. The first has a standard (canonical) answer. The second is because you are using a "raw" type. – Stephen C Mar 01 '21 at 07:18
  • The `ArrayList` class is a generic type and you should use it with a type parameter; e.g. `ArrayList list = new ArrayList();` or `ArrayList list = new ArrayList<>();` to avoid the "raw type" problem. Also, it is a good idea to do what the "Note:" message tells you to do! – Stephen C Mar 01 '21 at 07:25

0 Answers0