0
I have a problem, I have several variables (String) with the following names: textTransferd1, textTransferd2 to 73 (textTransferO73).
At certain times the variable textTransferd2 for example may take an empty value or not, depending on the situation.
I would like to mount an array, but I need to check if the String textTransferd1 to textTransferd73 is empty, but add to the array.
Just follow my code:
// INFORMATION RETRIEVAL
Bundle extra = getIntent().getExtras();
String textoTransferido1 = extra.getString("texto1");
String textoTransferido2 = extra.getString("texto2");
String textoTransferido3 = extra.getString("texto3");
String textoTransferido4 = extra.getString("texto4");
String textoTransferido5 = extra.getString("texto5");
String textoTransferido6 = extra.getString("texto6");
String textoTransferido7 = extra.getString("texto7");
String textoTransferido8 = extra.getString("texto8");
// CREATING THE ARRAY
final String[] frases =
{
textoTransferido1,
textoTransferido2,
textoTransferido3,
textoTransferido4,
textoTransferido5,
textoTransferido6,
textoTransferido7,
textoTransferido8
}
In the array I don’t know if it was right to create an array that would check each item and if not null then add the item in the array.
Since the array does not allow the item to be null or empty, I have to check the situation and only add the ones that have values.
Thank you.
You can simplify the code a little by modifying If to if(text != null && text.Trim(). length() > 0) text.add(text);
– Márcio Oliveira
Yeah, I know, I even thought I’d put it this way, but I thought it would be more readable the way I put it, silly thing.
– Leonardo Santos
it would not be more readable to have the comparison
texto.Equals(String.Empty)
?– mercador
What you could do is:
"".equals(texto)
, but it wouldn’t work for texts that only have spaces, which is why I used thetexto.trim ...
– Leonardo Santos
Thank you very much, Leonardo! Solved my problem, thanks for sharing your knowledge. Hug!!!
– Tisco