Java Programing laungage

java.util Projects

java.util Project 1

Comparing Arrays

This section of tutorials we show that how to determine the given arrays are same or not. The given program illustrates you how to compare arrays according to the content of array:

Previous Home Next

In this section of the tutorials, you can see that the given program initializes two arrays and input five number from user through the keyboard. And then the program checks whether the given taken both arrays are same or not. This comparison operation is performed by using the equals() method of Arrays class.


This method is used to compares two arrays.

Arrays is the class of the java.util.*; package. This class and it's methods are used for manipulating arrays.


package r4r;
import java.util.*;
public class comparearraytest {
public static void main(String[]args)throws IOException
	int[] array1 = new int[3];
int[] array2 = new int[3];
	  BufferedReader br = new BufferedReader
      (new InputStreamReader(;

	  System.out.println("Enter the 3 numbers for the first Array : ");
	  for(int i = 0; i < array1.length; i++){
	  array1[i] = Integer.parseInt(br.readLine());
	  System.out.println("Enter the 3 numbers for the second Array : ");
	  for(int i = 0; i < array2.length; i++){
	  array2[i] = Integer.parseInt(br.readLine());
	  catch(NumberFormatException e){

	  boolean check = Arrays.equals(array1, array2);
	  if(check == false)
	  System.out.println("Not same.");
	  System.out.println("Both Arrays are same.");

Previous Home Next