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.
List<List>. Read this which addresses your last snippet of code.List<List<Object>> table = new ArrayList<List<Object>>();and you're probably looking forList<List<?>> table = new ArrayList<List<?>>();but this still just storesObjectand not necessarilyStringor anything.