Problems whan passing a String inside a variable.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, February 1, 2002 10:46 AM

I've got the following method: public static boolean existeDispositivo(String nombreDispositivo) { Dispositivo dispositivo; Enumeration e = listaDispositivos.elements(); while(e.hasMoreElements()) { dispositivo = (Dispositivo)e.nextElement(); if (nombreDispositivo == dispositivo.getNombre()) { return true;} } return false; } where private static Vector listaDispositivos = new Vector(); "listaDispositivos" has objects "Dispositivo" in it. Dispositivos' constructor is: public Dispositivo(String nombreDispositivo) { try {    More>>

I've got the following method:

			
public static boolean existeDispositivo(String nombreDispositivo)
{
Dispositivo dispositivo;
Enumeration e = listaDispositivos.elements();

while(e.hasMoreElements())
{
dispositivo = (Dispositivo)e.nextElement();
if (nombreDispositivo == dispositivo.getNombre()) { return true;}
}
return false;
}


where

			
private static Vector listaDispositivos = new Vector();


"listaDispositivos" has objects "Dispositivo" in it.
Dispositivos' constructor is:

			
public Dispositivo(String nombreDispositivo)
{

try
{
nombre = nombreDispositivo;
listaDispositivos.addElement(this);
}
catch(Exception e)
{

}
}

and getNombre() method returns "nombre" variable from de corresponding "Dispositivo" instance.

When I call this method with an existing Dispositivo, passing the parameter by value, like this:

			
Dispositivo.existeDispositivo("sensor");


it works perfectly.
The problem is that I receive this parameter from the keyboard, among others, and I put all them in a StringTokenizer object. Then I put nombreDispositivo in a String variable and call the method like this:

			
Dispositivo.existeDispositivo(stringVariable);


and the method doesn't work, no matter if a "Dispositivo" with that "nombre" variable exists in the vector or not, it allways returns false. I must add that "nombre" uniquely identifies the "Dispositivo" instance.
I wonder if anybody can help me or tell me what I am doing wrong. Thanks.    <<Less

Re: Problems whan passing a String inside a variable.

Posted By:   Joey_Ogalesco  
Posted On:   Friday, February 1, 2002 11:51 AM

try this in your IF statement.

if ( nombreDispositivo.equals( dispositivo.getNombre()) )

Hope this will work.
About | Sitemap | Contact