[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using getText() with a JTextField component?



On Wed, 1 Aug 2001, D. Michael Nelson wrote:

> //The following line works - prints "Mike
> System.out.println(sName);
> 
> //This condition fails
> if (sName == "Mike")
>   System.out.println("yes");
> 
> Any suggestions?

Sure. This isn't a problem with getText, but a natural behavior of all
java Strings. Try this instead:

if (sName.equals("Mike")) ...

The "==" operator compares identity, not value..

Cheers,

- Michal
----------------------------------------------------------------------
let me host you! http://www.sabren.com       me: http://www.sabren.net
----------------------------------------------------------------------