Results 1 to 3 of 3
  1. #1
    jhetfield18 is offline Member
    Join Date
    Oct 2007
    Posts
    9
    Rep Power
    0

    Default HashTable problem

    Hi I have to make a HashTable.And I want to implement it by declaring an array of LinkedLists<Object> where the Object is a Connection struct that contains two strings.I declare it like this:
    private LinkedList<Connection>[] Connections;

    public HashTable(int m) {
    this.n = 0;
    this.m = m;
    //this.HS = hs;
    for (int i = 0; i < m; i++) {
    this.Connections[i] =new LinkedList<Connection> ();
    }
    }
    But its wrong and if I try the usual:
    private LinkedList<Connection>[] Connections=new LinkedList<Connection> [size];
    It throws a cannot create generic array of LinkedList<Connection>.
    What can I do to fix it????

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    int size = 5;
    // an array of Connections
    Connection[] connections = new Connection[size];
    // a LinkedList of Connections
    LinkedList<Connection> list = new LinkedList<Connection>();
    // an array of LinkedLists
    LinkedList[] lists = new LinkedList[size];

  3. #3
    jhetfield18 is offline Member
    Join Date
    Oct 2007
    Posts
    9
    Rep Power
    0

    Default

    thats good and all but that doesn't change the fact that I want to create an array of Linked Lists that store Connection objects and that basically you havem't answered my question.:P

Similar Threads

  1. HashTable vs HashMap
    By bugger in forum New To Java
    Replies: 7
    Last Post: 01-06-2011, 03:15 PM
  2. Working with Key-Value Pairs in a Hashtable
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:44 PM
  3. Hashtable example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:43 AM
  4. Hashtable-put method
    By new_1 in forum New To Java
    Replies: 1
    Last Post: 12-23-2007, 07:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •