Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 532769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:26:22+00:00 2026-05-13T09:26:22+00:00

I have a Hashtable of type Hashtable I’ve loaded several strings as keys, one

  • 0

I have a Hashtable of type Hashtable

I’ve loaded several strings as keys, one of which is “ABCD”

However, later when I go to look up “ABCD”, the Hashtable returns null instead of the associated object. Further the keyset contains “ABCD”, but a request to containsKey(“ABCD”) returns false.

Is this because String objects are inherently different objects?

If so, what is the write way to store information in a Hashtable if I want to use Strings as keys?

 public class Field {
        private String name;
        private DataType dataType;

        public Field(String name, DataType dataType) {
            this.name = name;
            this.dataType = dataType;
        }

        public String getName() {
            return name;
        }

        public DataType getDataType() {
            return dataType;
        }

        public String toString() {
            return name;
        }
    }

public class Record {
        private Hashtable<String, Data> content; 

        public Record(Field[] fieldList) {
            this.fieldList = fieldList;     
            content = new Hashtable<String, Data>();

            System.out.println(fieldList.length);

            for(Field f : fieldList) {          
                content.put(f.getName(), new Data());
            }
        }

        public void add(String field, String s) {
                    // ERROR OCCURS HERE IN THIS METHOD !!!

            System.out.println(field);

            for(String ss : content.keySet()) {
                System.out.print(" [ " + ss + " ] ");
            }
            System.out.println();

            System.out.println(content.containsKey(field));     
            System.out.println(content.get(field));

            content.get(field).add(s);
        }
}



public class Data {

    private Vector<String> lines;
    private int index;

    public Data() {
        lines = new Vector<String>();
        index = 0;
    }

    public void add(String s) {
        System.out.println("adding");
        lines.add(s);
    }

    public String nextLine() {
        try {
            return lines.elementAt(index++);
        } catch (ArrayIndexOutOfBoundsException aioobe) {
            return null;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:26:22+00:00Added an answer on May 13, 2026 at 9:26 am

    Works for me!

    import java.util.Hashtable;
    
    public class StrMap {
        public static void main(String[] args) {
            Hashtable<String,Object> map = new Hashtable<String,Object>();
            map.put("ABCD", "value");
            System.err.println(map.containsKey("ABCD"));
        }
    }
    

    Yo have probably made some other error. Reduce the problem to the smallest complete compilable program that still demonstrates the problem. You’ll probably find the problem straight away. If you don’t, at least you will have a question that we can answer.

    (Also Map and HashMap is that way to go. Hashtable is useful if you are using a pre-Java 2 API (Java 2 is comfortably over a decade old now!).)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a type of object called Bin , which has a hashtable field
I have a hashtable . values() method returns values in some order different from
I have to match two hashtable, but its keys does not match. So i
I have some code which populates a hashtable with a question as the key
If I have function names stored as strings in a Hashtable. Is there a
I have one key but different values for that key. I tried HashTable but
In .NET you can select a hashtable as type for a usersetting. However when
I have an array of type Guid inside an HashTable I get the values
I have a Hashtable object which names or map various fields in a class
I have a webmethod that returns a Hashtable through a jQuery ajax call along

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.