Java Snippet if else with strings

Hi everybody, 

I am trying to make a conditional with some string variables. I have a table like this one:

VAR A VAR B VAR C VAR D REV
A B C D X
A B C D Y
A B C D X
A B C D Y

I want to concatenate in a new column TEST= VAR A + VAR B + VAR C + VAR D if REV="X" else 

TEST = VAR C

The code that I wrote was this one, but it does not work 

out_TEST =c_VARA+" "+c_VARB+" "+c_VARC+" "+c_VARD;
if c_REV.equals("X") { 
	System.out.println(out_TEST);
}
else { 
	System.out.println(c_VARC);
}

Any help will be highly appreciated

Cheers

 

 

Hi,

and welcome to the exciting world of java snippets! Your code looks almost correct. The only thing wrong seems to be how you "store" the data. It is enough to just write the data into the right variable, with no extra method call. Something like this:

if c_REV.equals("X") {
   out_TEST = c_VARA + " " + c_VARB + " " + c_VARC + " " + c_VARD;
} else {
   out_TEST = c_VARC;
}

Cheers and good luck!

Marlin thank you for your help, I copied the code but I could not generate the new column. I wonder if could you please help me checking what is wrong. 

Cheers

 

 

 

Oups. Of course. I guess I should have tested it first.

if (c_REV.equals("X")) {
   out_TEST = c_VARA + " " + c_VARB + " " + c_VARC + " " + c_VARD;
} else {
   out_TEST = c_VARC;
}

Thank you