Syntax examples often used in Java


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.

Simple equation check strA.equals (strB)

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.

There is also this A == null

~~ Basically only String type. If you do it with other types, it will not work well. ~~

Recommended Posts

Syntax examples often used in Java
Gem often used in Rails
Matcher often used in RSpec
About methods often used in devise
Test API often used in AssertJ
Commands often used in MySQL operations
Ruby methods often used in Rails
Mechanism and characteristics of Collection implementation class often used in Java
Java control syntax
Java control syntax
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
Pi in Java
FizzBuzz in Java
[Gradle] Build operations often performed in Java projects
Organized memo in the head (Java --Control syntax)
About var used in Java (Local Variable Type)
[java] sort in list
[Java] Let's declare variables used in the loop in the loop [Variables in the block]
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Comments in Java source
Azure functions in java
[Java] Control syntax notes
Format XML in Java
Source used to get the redirect source URL in Java
Frequently used Java generics
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
Personal summary of the guys often used in JUnit 4
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
Syntax and exception occurrence conditions that can be used when comparing with null in Java
Things you often use when doing web development in Java
Try using RocksDB in Java