Jakkie Chan Jakkie Chan - 1 year ago 110
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download