Results 1 to 2 of 2
  1. #1
    alpdog14 is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default HastTable help containsKey

    I was wondering if anyone could help me, I have this lab project dealing with HashTables, it needs a containsKey and here is the code I put:

    Java Code:
    public boolean containsKey(K key) {
            int hashindex = hindex(key);
            Node<K,D> head = (Node<K,D>) hashTable[hashindex];
            if (hashindex == null) return false;
            else return true;

    But using BlueJ when I try to compile I get this error: incomparable types: int and <nulltype>

    Can anyone help me figure out why this occuring or what I need to fix? Any help would be most appreciated.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Quote Originally Posted by alpdog14 View Post
    Java Code:
           if (hashindex == null) return false;
    The line above doesn't make any sense; an int can never be null and that's what your compiler was whining about; it even gave you the line number in its error message.

    kind regards,


Similar Threads

  1. HashMap ContainsKey()
    By vinoopraj in forum Advanced Java
    Replies: 2
    Last Post: 03-25-2009, 10:19 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