Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two input column below, in user table external column holds True/False only.
So based on that True and False value we need to swap first name and last name.
Ex- If True then name will not swap else swap.

Java
user.external=(row4.external==null)?null:row4.external;
user.name=(row4.name==null)?null:row4.name;

Source Table:

              Name             external
--------------------------+---------------------
Vinod, Pratap (Corporate) |    False
   Anil Kumar (pilot.net) |     True
          Sukant, Mohanty |     True


When the external column is "True" then output will be below in target table and where is "False" in external column then the name will be swap.
Also the code will skip (Corporate),(pilot.net) as well.

Target Table(Output):
FirstName   Last Name
----------+-----------
     Anil |Kumar 
   Sukant |Mohanty
   Pratap |Vinod


What I have tried:

Java
String str =(row4.external.toString()==True)?True:row4.external.toString();
if(str = True {
String[] strArray = str.split(",");
Posted
Updated 11-May-20 23:42pm
v2

1 solution

You cannot compare a string to a boolean value or assign a boolean to a string:
Java
String str =(row4.external.toString() == "True") ? "True" : row4.external.toString();
if(str == "True" {
    String[] strArray = str.split(",");
}

although a less complex way would be:
Java
String[] strArray;
if (row4.external.toString() == "True")
{
    strArray = str.split(",");
}
else {
    strArray = new String[1];
    strArray[0] = row4.external.toString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900