Question: It may be asked somewhere but I could not find it.

Please tell me the exact difference between:

```
ArrayList list = new ArrayList();

```

and

```
ArrayList<?> list = new ArrayList();

```

I cannot figure out what is the exact difference between these two.

Thanks...

Answer: 
```
ArrayList list = new ArrayList();

```

We are declaring an array list that can accept any type of objects.

For example:

```
list.add(new Dog());
list.add(new Person());
list.add("Test");

```

For `ArrayList<?> list = new ArrayList();`

We are declaring an array list using generics that can accept any object using the wild card **?**

The catch here is that we cannot add elements to that array list.

This code will not even compile:

```
ArrayList<?> list = new ArrayList();
list.add("test");

```

**Update**:

I think the only purpose of the ? wild card in generics is to be coupled by the extends keyword.

```
ArrayList<? extends Animal> list = new ArrayList<Dog>();

```

In that case we add any object to **list** that extends the **Animal** object

or to be passed to as a parameter to a method.

```
public void foo(List<?> list) { }

```

In that case the method **foo** cannot add objects to the parameter **list**
ArrayList < ? > means array list of type unknown. it is called a wildcard type.

Using the wild card, the following occurs

```
Collection<?> c = new ArrayList<String>();
c.add(new Object()); // Compile time error

```

Without the wildcard you can add whatever you like to your array