How to get the Checksum of a Byte Array in Java?

Create a Byte Array for which you want the Checksum −

byte[] arr = "This is it!".getBytes();

Now, create a Checksum object −

Checksum checksum = new Adler32();
checksum.update(arr, 0, arr.length);

The update() above updates the current checksum with the specified array of bytes.

Now, get the checksum with getValue() method, which gives the current checksum value.

Example

import java.util.zip.Adler32;
import java.util.zip.Checksum;
public class Demo {
   public static void main(String[] argv) throws Exception {
      byte[] arr = "This is it!".getBytes();
      Checksum checksum = new Adler32();
      checksum.update(arr, 0, arr.length);
      long res = checksum.getValue();
      System.out.println("Checksum of a Byte array = "+res);
   }
}

Output

Checksum of a Byte array = 391709619
Updated on: 2026-03-11T22:50:44+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements