Skip to content

Instantly share code, notes, and snippets.

@gitmatheus
Last active April 11, 2017 20:41
Show Gist options
  • Save gitmatheus/70907a131683ff8be42dc47c3c9be779 to your computer and use it in GitHub Desktop.
Save gitmatheus/70907a131683ff8be42dc47c3c9be779 to your computer and use it in GitHub Desktop.
// First, let's declare a list of Strings,
// using the previous String variables:
String[] stringsToConcat =
new String[]{singleSpaceString, nullString, notEmptyString};
// Now we can use a join method to concatenate the variables:
String joinedText = String.join(stringsToConcat, '');
// This is the result:
|DEBUG|concatenated joinedText: Samwise Gamgee is the real hero
// Note the null value was not added to String this time.
// Let's concatenate only the null and empty strings:
stringsToConcat = new String[]{singleSpaceString, nullString};
joinedText = String.join(stringsToConcat, '');
// Now, the interesting part:
// let's find out if this variable is Empty or Null:
Boolean isBlank = String.isBlank(joinedText);
Boolean isEmpty = String.isEmpty(joinedText);
|DEBUG|concatenated isBlank: true
|DEBUG|concatenated isEmpty: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment