Searching for a String in a Hashtable - Java
<p>I'm having trouble searching a Hashtable for a particular String xmlMatch. This is derived from the contents of a particular div tag  </p>

<p>I have included the code I use to search the XML and to define the String xmlMatch. I believe this is right and have shown so by printing it to the screen. I know this should be simple. I have created a quick test Hashtable and the same thing works there.</p>

<p>My TEST CODE - Works</p>

<pre><code>String xmlMatch2 = "Two";
Hashtable&lt;String, String&gt; table2 = new Hashtable &lt;String, String&gt;();
table2.put("One", "Uno");
table2.put("Two", "Dos");
table2.put("Three", "Tres");

System.out.println(table2.containsKey(xmlMatch2));
String n = table2.get("Two");
System.out.println(n);
</code></pre>

<p>Works as expected, Prints the following to the console in Eclipse</p>

<p>true</p>

<p>DOS</p>

<p>My PRODUCTION CODE - Not Working</p>

<pre><code>if(startPosition &gt;1)            
{
    out.println("startPosition is greater or equal to 1 ");

    int subStringIndex = startPosition + startTag.length();
    subStringIndex = subStringIndex + 2; // +2 is necessary to remove "&gt; after sliceXML             
    out.println(subStringIndex); 

    int endPosition = testContent.indexOf(endTag, subStringIndex);
    out.println(endPosition); 

    if(endPosition &gt;= startPosition)
    {

    xmlMatch = testContent.substring(subStringIndex, endPosition);
    //out.println("This is my xmlMatch " + xmlMatch); //prints Florida
    }
</code></pre>

<p>The above print statement (when activated) confirms that xmlMatch is Florida    </p>

<p>I then implement a simple Hashtable </p>

<pre><code>Hashtable&lt;String, String&gt; table = new Hashtable&lt;String, String&gt;();
    table.put("Florida","/PathToFile.txt");
    table.put("Telescope","/PathToFile2.txt");
    table.put("Galaxy","/PathToFile3.txt");
</code></pre>

<p>This is where my problems start!</p>

<pre><code>out.println(table.containsKey(xmlMatch));
</code></pre>

<p>The above print statement prints false to the screen - I believe it should print true as xmlMatch which equals Florida is in the Hashtable.</p>

<pre><code>String n = table.get(xmlMatch);
out.println(n); 
</code></pre>

<p>And this prints null - I believe this should print /PathToFile.txt</p>

<p>However if I simply do this</p>

<pre><code>out.println(xmlMatch);
</code></pre>

<p>It once again prints Florida to the screen</p>

<p>What am I doing wrong? I simply want to be able to search my Hashtable for a particular String. Any help is as always, much appreciated. </p>

<p><strong>EDIT:</strong>
Is it possible that I am having an issue with capital letters, or maybe my xmlMatch is passing an additional space character? e.g. "Florida " </p>

<p><strong>EDIT 2</strong>
My xml div tag simply reads </p>

<pre><code>&lt;sliceXML&gt;Florida&lt;/sliceXML&gt;
</code></pre>

<p><strong>WORK AROUND SOLUTION</strong>
Im adding this here as it is a solution to the problem but not to the question i asked.</p>

<p>with the help of <a href="http://stackoverflow.com/users/854793/joe-k">Joe K</a> i checked my endTag and found that i was nto able to encode the forward slash properly. I posted my work around answer <a href="http://stackoverflow.com/questions/12285142/encoding-special-html-characters-in-java">here</a></p>
