I'm developing more often in Java, so I'll post the syntax I'm using. Since it is a basic syntax, you may take it for granted, but I hope you can see it as if it were a memo. StringUtils.isEmpty()
String str = "Hello";
if (StringUtils.isEmpty(str)) { }
As a usage, it is used when checking whether it is empty or null. I often use it because null check can be done with this. It is better to use Optional for Java these days, but it is still a popular notation. There is also isEmpty, but it is better to use StringUtils.isEmpty because it is not null checked.
ObjectUtils.isEmpty() It works the same as StringUtils.isEmpty (), it is done for Object, so check it after putting the data acquired by API etc. in Entity. If the API acquisition is not successful and the Object is not created correctly, it will return false.
private static final String RESULT_CODE = "OK";
//The result of some API
String apiResult = nanikanoApi();
if (RESULT_CODE.equals(apiResult)) {}
It is used in this way. The RESULT_CODE side must be a constant or fixed value that is not null. Note that if you set a null value, you will get a NullPointerException. Please process the value you want to compare on the apiResult side.
~~ Basically only String type. If you do it with other types, it will not work well. ~~
Recommended Posts