Last active
April 11, 2017 20:41
-
-
Save gitmatheus/70907a131683ff8be42dc47c3c9be779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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