code_junkie

Cannot create an array of LinkedLists in Java…?

Nov 11th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. private LinkedList<IntegerNode>[] myMatrix;
  2.  
  3. myMatrix = new LinkedList<IntegerNode>[numRows];
  4.  
  5. List< List<IntegerNode>> nodeLists = new LinkedList< List< IntegerNode >>();
  6.  
  7. class IntegerNodeList {
  8. private final List< IntegerNode > nodes;
  9. }
  10.  
  11. myMatrix = (LinkedList<IntegerNode>[]) new LinkedList[numRows];
  12.  
  13. private Map<Integer, Map<Integer, IntegerNode>> myMatrix = new HashMap<Integer, Map<Integer, IntegerNode>>();
  14.  
  15. // access a matrix cell:
  16. int rowIdx = 100;
  17. int colIdx = 30;
  18. Map<Integer, IntegerNode> row = myMatrix.get(rowIdx); // if null, create and add to matrix
  19. IntegerNode node = row.get(colIdx); // possibly null
  20.  
  21. LinkedList<String>[] array = (LinkedList<String>[]) new LinkedList[6];
  22. array[0].add("Ahmed");
  23.  
  24. List<String>[] lst = new List[2];
  25. lst[0] = new LinkedList<String>();
  26. lst[1] = new LinkedList<String>();
Add Comment
Please, Sign In to add comment