Search code examples
javaconditional-statementstalend

Talend (if, else) in tJavaRow module


I'm trying to add informations in one column by using tJavaRow module and using conditional expression. The target here is simple. If "Fonction_libelle" column containt "DIRECTEUR" information, add in "Directeur_Oui_Non" column "Oui" else add "Non". I tried this :

if (input_row.Fonction_libelle == "DIRECTEUR") { output_row.Directeur_Oui_Non = "Oui";} else {output_row.Directeur_Oui_Non = "Non";}

The output of this is i've got "Non" everywhere but there are some "DIRECTEUR" in "Fonction_libelle" column. Of course there is something wrong but i'm not able to see what...

enter image description here

Any help would be very appreciated !


Solution

  • Try with .equals() instead of ==

    if ("DIRECTEUR".equals(input_row.Fonction_libelle)) {
     output_row.Directeur_Oui_Non = "Oui";}
     else {output_row.Directeur_Oui_Non = "Non";}
    

    "==" is not recommended to compare strings