A few tips when using String or Collection part 1

Tram Ho

Hello everyone, today I will share about the tip of checking String null or full space conveniently

I will use the library StringUtils class to download the jar file to import into the library at ( link )

If you use maven project, it’s easier, just import in pom.xml file

If you want to check if the String is null / full space / empty, then manually check will be like this

Output

Very long and messy, right?

Now if we use the library, we just need to do this

Output

Still the same, very convenient, right?

If you do not want to check the fullspace, use the following method:

Output

StringUtils has many other libraries that you can check and use for your purposes. For example, isNotBlank (), isNotEmpty () …

Now let’s move on to validate Collections in java

Maven project, then add this paragraph to pom.xml file:

And java projects usually import jar file to download at the link

An example of checking whether that Collection is empty or null

Output

This is just one of the functions of the CollectionUtils class, depending on the purpose of the use you get to use.

Thank you for reading all of your post, if something went wrong, please comment for me to correct it

My Fanpage: https://www.facebook.com/morethanacoder

His utube : thanglaptrinh

Share the news now

Source : Viblo