I'm new to Java, but I like it!
I am using NetBeans7.2, and when I try to create an ArrayList as follows:
ArrayList<String> list = new ArrayList<>();
NetBeans says that "the ArrayList type does not accept parameters" (which does not make sense, since my code is simple and correct for Java7).
Also, when I try to import:
import java.util.ArrayList;
NetBeans says: "ArrayList is already defined in this compilation unit."
You no longer need to import ArrayList?
Thank you very much! Please forgive my bad English;)
EDIT: Here is my complete code (this is just an exercise)
import java.util.ArrayList; public class ArrayList { public static void main(String[] args) { ArrayList<String> cores = new ArrayList<>(); cores.add("Branco"); cores.add(0, "Vermelho"); cores.add("Amarelo"); cores.add("Azul"); System.out.println(cores.toString()); System.out.println("Tamanho= " + cores.size()); System.out.println("Elemento2= " + cores.get(2)); System.out.println("Indice Branco= " + cores.indexOf("Branco")); cores.remove("Branco"); System.out.println("Tem Amarelo?" + cores.contains("Amarelo")); } }
source share