Aaleks
Aaleks

Reputation: 4343

Java create list problems with List<Type> myList = new ArrayList<Type>();

I want to create list by doing this

List<String> myList = new ArrayList<String>();

but it's not recognized, i don't know why:

Eclipse suggest me to modify the syntax :

First eclipse consider that the type List is not generic and it removes the first String brackets

List myList = new ArrayList<String>();

and then change the type of my List and finally i have :

ArrayList<String> myList = new ArrayList<String>();

I really don't understand why it doesn't work.

How to make a new List in Java I read this post and try again with an other type it's the same problem.

EDIT:my code look like this

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

    public class Test {

        public static void main(String[] args){
            List<String> myList = new ArrayList<String>();
    }
}

The problem was solved by changing

import java.awt.List;

to

import java.util.List;

Upvotes: 2

Views: 2054

Answers (1)

Harmlezz
Harmlezz

Reputation: 8068

Does your code look like this?

import java.util.ArrayList;
import java.util.List;

public class Example {

    public static void main(String[] args) throws Exception {
        List<String> myList = new ArrayList<String>();
    }
}

Upvotes: 1

Related Questions