简体   繁体   中英

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;

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>();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM