Trying to find the indexOf a string from an ArrayList filled with strings from hashtable, only returning -1
<p>I am trying to get the indexOf of a specific string from an ArrayList but the string is not matching when doing the check.  I am filling the StringList from hashtable with the code below.</p>

<pre><code>stringList = new ArrayList&lt;String&gt;

Set st = hashtable.keySet();
Iterator itr = st.iterator();
while(itr.hasNext())
{
  stringList.add(((String)itr.next()).trim());
}
</code></pre>

<p>The string I am trying to get from the stringList is input by the user, the string is generally in the form of “! Xxxx ##:##:## xx” if that makes a difference.  I know the string match in the fact that I test it visually by printing out the stringList. So I figure it is something similar to the == and .equals().</p>

<p>I tested also by filling the stringList with a specific String from the hashtable and using the code below and it always returns false.</p>

<pre><code>String keyString = "! Xxxx ##:##:## xx";
if(stringList.get(0).equals(keyString))
   System.out.println("true");
System.out.println("false");
</code></pre>

<p>So I am trying to figure out how to get the code below to work</p>

<pre><code>stringList.indexOf(keyString)
</code></pre>

<p>because it only returns -1 which it should, as it is not seeing the strings are equal. What am I doing wrong that is preventing the output I am looking for, which would be the correct index that I think it should be returning since I am typing exactly what is being print out by stringList. Like I said before, I thought it was an issue with .equals() but from what I can tell indexOf uses .equals() when looking for the index as well as seeing the results from me testing .equals() myself.</p>
