After going through many posts and suggestions, I have found that instead of using a concrete implementation such as ArrayList, I should use List instead, to allow flexibility between different implementations of the List Interface. So far, I have seen that many programmers suggest the following line of code:
List list = new ArrayList();
However, this would give a warning in the compiler for using the raw types List and ArrayList and that they should actually be parameterized.
Synonymous to these warnings, I have found several posts telling me that raw types should never be used and that I should take advantage in using generics that java offers so conveniently.
Personally, I am trying to implement a class that acts as a table requiring a 2 Dimensional List structure with ArrayLists being used internally. I am trying to implement the following lines of code:
List<List> table;
table = new ArrayList();
table.add(new ArrayList());
Envisioned in my head, the table structure should be able to hold multiple variable types such as the raw data types along with the String variable type. I have tried to implement generics such as using
List<List<Object>> table = new ArrayList<ArrayList<Object>>();
but I have received many errors and hence failed so far.
I am relatively new to programming, pursing a computer science major, so forgive me if I have any horrible misunderstanding of the lines of code that I have exemplified above.
Thank You.
`. Read [this](http://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-arent-javas-generics-implicitly-p) which addresses your last snippet of code.
– Sotirios Delimanolis Dec 16 '14 at 14:48> table = new ArrayList
– EpicPandaForce Dec 16 '14 at 14:51>();` and you're probably looking for `List
> table = new ArrayList
>();` but this still just stores `Object` and not necessarily `String` or anything.