0

I know it's a silly question but here's my issue.

I'm working on an object and needed to check all the member variables for nullity, empty chars etc... but in my object I don't only have strings, I also have Instant and Booleans.

I've tried with some other methods from StringUtils and read the documentation but didn't find out any way to do so.

Any tip ? I know i can make the check without stringUtils but I can't believe they didn't figured a way out.

Thank you for your help!

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
raik
  • 33
  • 2
  • 13
  • 1
    So you wonder why a class named ___String___ Utils doesn't include stuff to check `boolean` and `Instant`? – Tom Feb 08 '17 at 22:33

1 Answers1

0

You can use Objects class from java.util package to perform null checks in different type of objects, e.g.:

Date d = null;
Character c = new Character('c');
System.out.println(Objects.isNull(d));
System.out.println(Objects.isNull(c));

You can also use methods like requireNonNull to validate the values before sending to a method or a service.

Here's javadoc for Objects class.

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102