Pregunta

I am experiencing some strange issues with request.getParameter("param") in Java. I am trying to test the returned value to set a boolean, nothing fancy. :)

String param = String.valueOf(request.getParameter("param"));
boolean paramIsAll = false;
if (param == "all"){paramIsAll = true;}

System.out.println("-"+ param +"-"+ String.valueOf(paramIsAll));

My output is: -all-false

???

¿Fue útil?

Solución

try with if (param.equals("all")){paramIsAll = true;}

while comparing 2 strings use String#equals()

Otros consejos

Try: If(param.equalsIgnoreCase("all")){paramIsAll = true;}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top