+ 2

Add() method not exist in ArrayList class ! ?

I tried to add new elements to an ArrayList, but there is no add method shown in eclipse...

19th Jun 2017, 9:05 AM
Shooresh Sufiye
Shooresh Sufiye - avatar
3 odpowiedzi
+ 2
The problem was with ArrayList declaration! If following regular way of declaration didn't work >> ArrayList<String> colors = new ArrayList<String>(); try this kind of definition: >> java.util.ArrayList<String> colors = new java.util.ArrayList<>(); It works for me.
19th Jun 2017, 8:08 PM
Shooresh Sufiye
Shooresh Sufiye - avatar
0
the add method does exist. Just make sure you write it in small letters and that you use it properly. Eg. ArrayList <String> myArr = new ArrayList<String>(); //using the add method myArr.add("anyString");
19th Jun 2017, 10:55 AM
Noobie
Noobie - avatar
0
Java naming conventions: class name - starts with capital letter methods, objects and variables - lower letter, camel case package name - all lower letter case constants - all capital letter separated by underscores.
19th Jun 2017, 12:31 PM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar