Brett McLaughlin wrote:
> 
> Scott Tavares wrote:
> >
> > Does anyone know of an ease and efficient way to do this? right know the
> > code i have looks:
> >
> >    int index = tableNameSet.indexOf(tableName);
> >    if(index != -1){
> >     tableNameSet.addElement(tableName);
> >    }

Besides, you should really do:

<code>
  if (!tableNameSet.contains(tableName))
      tableNameSet.addElement(tableName);
</code>

Better, better ;-)

-Brett

> >
> > but what is happening (i think) is the indexOf() method to comparing copies
> > of references of the string instead of comparing the literal values stored
> > in them (the way java does comparisons is so freaking confusing).
> 
> what class is this in?  i need to know more - what is the type of
> tableNameSet variable?  If it is a vector, like it looks:
> 
> performing indexOf() on a Vector uses the Objet's equals() method, which
> results in a comparison that is fairly shallow.  However, because of the
> literal String pool in Java, (string1 == string2) is exactly the same as
> string1.equals(string2).  Keep in mind that in both cases, the case _is_
> sensitive.  So if you added tableName earlier as a String, this should
> work fine.
> 
> BTW, you might want to bookmark the APIs, they can clear up this type of
> confusion:
> 
> http://java.sun.com/products/jdk/1.3/docs/api/index.html
> 
> that's JDK 1.3, but you get the idea ;-)
> 
> -Brett
> >
> > anyone?....... anyone?......
> >
> > -scott-
> >
> > ------------------------------------------------------------
> > To subscribe:        [EMAIL PROTECTED]
> > To unsubscribe:      [EMAIL PROTECTED]
> > Problems?:           [EMAIL PROTECTED]
> 
> ------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Problems?:           [EMAIL PROTECTED]


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to