Question: Please help me understand, the below code is showing Type mismatch: "cannot convert from element type Object to List" in the for statement. I know I'm missing something silly. Please help.

```
public void setMapPriceValue(SolrItemVO solrItemVO, ArrayList proce1) throws SolrDAOException
{
    List xcatentAttrList = (List<Xcatentattr>) proce1.get(0);

    solrItemVO.setMapPrice(-1); // setting default value

    for(List  xcatentattr : xcatentAttrList){

        if(xcatentattr.get(0) == 33)

                solrItemVO.setMapPrice(xcatentattr.get(1));

                solrItemVO.setMapPriceVal(xcatentattr.get(2));

        }

}

```

Answer: 
First you are mixing generics and raw types - it would make your life easier if you only used generics:

```
List<Xcatentattr> xcatentAttrList = (List<Xcatentattr>) proce1.get(0);

```

You might also consider using the correct generic type in your method signature (I assume `proce1` is a list of list):

```
public void setMapPriceValue(SolrItemVO solrItemVO, List<List<Xcatentattr>> proce1)

```

In which case you don't need the cast any more:

```
List<Xcatentattr> xcatentAttrList = proce1.get(0);

```

Then the syntax for the enhanced for loop is `for (TypeOfObjectInYourList object : list)`, so in your case:

```
for(Xcatentattr xcatentattr : xcatentAttrList)

```
There are two issues here.

* First, if you declare `List xcatentAttrList` without using generics, Java can only know that your list contains `Object`s. So your `for` loop would have to iterate through a list of `Object`s.
* Second, the cast `(List<Xcatentattr>)proce1` implies the list contains `Xcatentattr` elements, and yet you are iterating through `List` objects.

So provided you had declared the `List` using generics (and therefore saying you are working with a list of `Xcatentattr` elements), the loop `for` would be:

```
 for (Xcatentattr xcatentattr : xcatentAttrList) {
     . . .
 }

```