Here I have an array of LinkedLists of the string type. I'm trying to store the string in the hash code index of my array but I'm getting a Null Pointer exception when i try to add it. Does this have to do with my casting or am I implementing this whole thing incorrectly. Any help would be greatly appreciated. Here is the code:
public class Hash { public static void main (String[] args){ //Scanner input=new Scanner(System.in); //System.out.println("Enter your string: "); String s="aaba1xxfsf"; int h=Math.abs(s.hashCode())%100000; System.out.println("hash code is: "+h); @SuppressWarnings("unchecked") LinkedList<String>[] list=(LinkedList<String>[])new LinkedList[10000]; list[h].add(s);//Null pointer exception happens here for(LinkedList<String> i: list){ if(i!=null) System.out.println("Your string is at index "+i); } } }