Problem with ArrayList

3

I'm learning about Array and I'm breaking my head with this code, can anyone explain why it's not working?

This error appears

  

The type List is not generic; it can not be parameterized with   arguments

in this line List<Integer> lista = new ArrayList<Integer>();

package DeclaracaoArray;

import java.awt.List;
import java.util.ArrayList;
import java.util.Collections;

public class Declaracao_Array {


    public int sorteia(){
            List<Integer> lista = new ArrayList<Integer>() ;

            lista.add ( "Alice" ) ;
            lista.add ( "Bruno" ) ;
            lista.add ( "Carlos" ) ;
            lista.add ( "Daniel" ) ;

   Collections.shuffle ( lista ) ;

       // pega qualquer indice. pegamos o primeiro para conveniencia.

       return (( Integer ) lista.get ( 0 )).intValue () ;
    }
}
    
asked by anonymous 29.09.2015 / 14:54

2 answers

6

You imported the wrong package:

import java.awt.List;

When in fact it was meant to be:

import java.util.List;

As you can see in the documentation List you did not use generics, while the List you wanted to use Yes.

    
29.09.2015 / 15:00
5

You are defining that the list will contain variables of type Integer while you are populating with variables of type String which are the names.

If you are not going to add a value that type is different from String declare the list variable like this:

List lista = new ArrayList();

Or

List<String> lista = new ArrayList<String>();
    
29.09.2015 / 14:58