I have a class which holds a list inside a list, and its declared as type String, but i no longer know that its a string.
private ArrayList<List<String>> table;
table = new ArrayList<List<String>>();
table.add(new ArrayList<String>()); //is possible
table.add(new ArrayList<Integer>()); //not possible
But now the nested list could either be string or integer. How can i fix that? I also can't declare Object must either be string or integer
Also can a single Arraylist hold both ints and strings without declaring as objects?
Edit: It seems you guys are debating the right answer. I will insight why i chose Vikdor answer.
My job is to load a csv, and then user types in command to define each column as string or int. My table class has a private instance variable, and has methods which adds the values. Doing it in Vikdor way makes performing operations on table very easy where i want to merge two table or sort. It will also prevent user from inputting non string or int through an exception.