

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compare two-byte arrays in a single line in Java
Two byte arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order. A program that compares two byte arrays using the Arrays.equals() method is given as follows −
Example
import java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { boolean flag = Arrays.equals(new byte[] { 1, 7, 5 }, new byte[] { 1, 7, 5 }); System.out.println("The two byte arrays are equal? " + flag); } }
Output
The two byte arrays are equal? true
Now let us understand the above program.
The Arrays.equals() method is used to compare two byte arrays. If they are equal then true is stored in flag and if they are not equal then false is stored in flag. The value of flag is displayed. A code snippet which demonstrates this is as follows −
boolean flag = Arrays.equals(new byte[] { 1, 7, 5 }, new byte[] { 1, 7, 5 }); System.out.println("The two byte arrays are equal? " + flag);
- Related Questions & Answers
- Compare two int arrays in a single line in Java
- Compare two short arrays in a single line in Java
- Compare two double arrays in a single line in Java
- Compare two long arrays in a single line in Java
- Compare two float arrays in a single line in Java
- Compare two char arrays in a single line in Java
- Java Program to compare two Byte Arrays
- Compare Two Java int Arrays in Java
- Compare Two Java long Arrays
- Compare Two Java double arrays
- How to compare two arrays in Java?
- How do we compare two arrays in Java?
- Java Program to compare two Boolean Arrays
- Java Program to compare two Java char Arrays
- Java Program to compare Two Java short Arrays
Advertisements