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.

Request to add nonNullOrEmpty method to Strings class

See original GitHub issue

I request to add the nonNullOrEmpty method to the String class. When use stream, can use method reference to write whether the string is null or empty.

stringStream.filter(Strings::nonNullOrEmpty) ...

I think this is useful. What do you think?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
cgdeckercommented, Mar 12, 2018

Though we do have some methods (well, Strings.isNullOrEmpty(), at any rate) that do so, we generally don’t encourage methods that treat null and non-null values the same. There are a lot of ways you could deal with this situation without us needing to add a new method:

  • filter(not(Strings::isNullOrEmpty)) (Guava’s Predicates.not())
    • or filter((Strings::isNullOrEmpty).negate()), but this probably doesn’t work without casting Strings::isNullOrEmpty to Predicate<String>
  • map(Strings::emptyToNull).filter(Objects::notNull)
  • etc.
0reactions
try0commented, Mar 12, 2018

@cgdecker Thank you for presenting an example. I’ll use those.

Read more comments on GitHub >

github_iconTop Results From Across the Web

String.IsNullOrEmpty(String) Method (System) - Microsoft Learn
IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is null or its value is String.Empty. It is...
Read more >
Is extending String class with IsNullOrEmpty confusing?
IsNullOrEmpty (yourString) method. I was wondering if it's going to confuse developers or make code better if we extend String class to have...
Read more >
C# | IsNullOrEmpty() Method - GeeksforGeeks
In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A...
Read more >
String.IsNullOrEmpty() method with example in C#
String.IsNullOrEmpty() method is a built-in method of String class and it is used to check whether a string is Null or Empty? If...
Read more >
Checking for Empty or Blank Strings in Java - Baeldung
Check out some simple ways in Java to test if a string is blank or ... Of course, it's pretty common to know...
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