0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

byte[] 型の配列が空であるかどうかを Java でチェックする

Last updated at Posted at 2024-09-30

標準ライブラリ

byte[] byteArray = ...; // ここに配列を初期化するコードが入ります。

if (byteArray == null || byteArray.length == 0) {
    System.out.println("The byte array is empty.");
} else {
    System.out.println("The byte array is not empty.");
}

Apache Commons Lang

import org.apache.commons.lang3.ArrayUtils;

byte[] byteArray = ...; // ここに配列を初期化するコードが入ります。

if (ArrayUtils.isEmpty(byteArray)) {
    System.out.println("The byte array is empty.");
} else {
    System.out.println("The byte array is not empty.");
}

Google Guava

import com.google.common.primitives.Bytes;

byte[] byteArray = ...; // ここに配列を初期化するコードが入ります。

if (Bytes.asList(byteArray).isEmpty()) {
    System.out.println("The byte array is empty.");
} else {
    System.out.println("The byte array is not empty.");
}

Spring Framework

import org.springframework.util.ObjectUtils;

byte[] byteArray = ...; // ここに配列を初期化するコードが入ります。

if (ObjectUtils.isEmpty(byteArray)) {
    System.out.println("The byte array is empty.");
} else {
    System.out.println("The byte array is not empty.");
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?