Jakkie Chan Jakkie Chan - 5 months ago 15x
Java Question

Inserting to an ArrayList of LinkedList


array = new ArrayList<LinkedList<String>>(size);

Trying to insert with this line:


It return an error saying "The type of the expression must be an array type but it resolved to ArrayList<\LinkedList<\String>>"

I'm trying to insert a string into a linkedlist node in an array index using the add linkedlist method. Why isn't that line working?

*This is a hashmap implementation btw, an array of linked lists


Arrays use the [] operator. Other types (such as Lists) can't, and must use methods (such as get) to access their elements: