An array cannot have a component type that is a parametrized type, or I should say its not useful. Basically due to type erasure, the type of the array is not known, which causes the array store check to fail.
LinkedList<String>[] table is causing your issue. The argument passed into the method cannot be of type LinkedList<String>[] because its impossible to instantiate such a type in Java.
Try the following line in your IDE, which won't compile:
LinkedList<String>[] list = new LinkedList<String>[];
Try using a:
List<LinkedList<String>> instead of LinkedList<String>[]
See the Generic Faq
Working Example
I had to stub a bunch of methods, but here is a working example:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class ArrayStoreCheck {
public static void main(String[] args) {
List<LinkedList<Anagram>> lists = new ArrayList<LinkedList<Anagram>>();
LinkedList<Anagram> anagrams = new LinkedList<Anagram>();
lists.add(anagrams);
List<String> dictionary = new ArrayList<String>();
dictionary.add("one");
dictionary.add("two");
populateLinkedList(lists, dictionary);
System.out.println(lists.get(0).get(0));
}
private static void populateLinkedList(List<LinkedList<Anagram>> table, List<String> dictionary){
for(String s:dictionary){
String temp=findHash(s);
int hashKey=hashFunction(temp);
Anagram obj=new Anagram(s, temp, hashKey);
table.get(hashKey).add(obj);
}
}
//Stub
private static String findHash(String s){
return "";
}
//Stub
private static int hashFunction(String s){
return 0;
}
//Stub
public static class Anagram{
private String s;
public Anagram(String s, String t, int key){
this.s = s;
}
@Override
public String toString() {
return s;
}
}
}
...when I try to call the LinkedList method add it doesn't work.Do you get an exception of some type or what does it do to "not work?"hashTable? There is no way to instantiate aLinkedList<String>[]so the method cannot be being passed the right parameter.ArrayStoreException?LinkedList<String>[] arr = null;outside of the method.