question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Strings.nonEmpty(String)

See original GitHub issue

Please add the following function to Strings in order to allow testing for non-empty strings in Streams or Optionals:

public static boolean nonEmpty(@Nullable String s) {
    return s != null && !s.isEmpty();
}

This follows the pattern of Objects.nonNull.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
perceptron8commented, Oct 30, 2018

Duplicate of #3064?

1reaction
jrtomcommented, Oct 30, 2018

I can understand wanting to do that, but I think it’s highly unlikely that the Guava team is going to introduce a new method whose semantics are the negation of an existing method to save people from having to do this:

filter(s -> !isNullOrEmpty(s))

I mean, method references are nifty but lambdas make this pretty painless IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Add to string if string non empty - Stack Overflow
Here is one option that I like. It's better if you already have an IEnumerable<string> with your data, but it's easy enough even...
Read more >
Nonempty strings - Type Classes
If the input is equal to an empty string, for example, then we could return False, otherwise we would apply the isPalindrome function...
Read more >
Is there a single word for a "non-empty" string?
I wouldn't call it "full". "Non-empty" or "non-null" works, but is there not a single word that unambiguously captures the meaning of "not...
Read more >
Concatenating Null Strings in Java - Baeldung
Learn various approaches to avoid null String objects while concatenating Strings in Java.
Read more >
Join non-Empty Strings with a Separator in JavaScript
The join method takes a separator as a parameter and joins the array elements into a string based on the provided separator. Here...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found