Friday, October 31, 2014

Java Array



Compare Two Java boolean Arrays

import java.util.Arrays;
public class CompareBooleanArraysExample
{
public static void main(String[] args)
{
boolean[] blnArray1 = new boolean[]{true,false,true};
boolean[] blnArray2 = new boolean[]{true,false,true};
boolean blnResult = Arrays.equals(blnArray1,blnArray2);
System.out.println("Are two boolean arrays equal ? : " + blnResult);
   }
}

Compare Two Java byte Arrays

import java.util.Arrays; 
public class CompareByteArraysExample
{
public static void main(String[] args)
{
byte[] byteArray1 = new byte[]{7,25,12};
byte[] byteArray2 = new byte[]{7,25,12};
boolean blnResult = Arrays.equals(byteArray1,byteArray2);
System.out.println("Are two byte arrays equal ? : " + blnResult);
  
   }
}

Compare Two Java char Arrays

import java.util.Arrays;
public class CompareCharArraysExample
{
public static void main(String[] args)
{
char[] charArray1 = new char[]{'d','h','r','f'};
char[] charArray2 = new char[]{'d','h','r','f'};
boolean blnResult = Arrays.equals(charArray1,charArray2);
System.out.println("Are two char arrays equal ? : " + blnResult);
   }
}

Compare Two Java double Arrays

import java.util.Arrays;
public class CompareDoubleArraysExample
{
public static void main(String[] args)
{
double[] dblArray1 = new double[]{10.3221,789.23,427.213};
double[] dblArray2 = new double[]{10.3221,789.23,427.213};
boolean blnResult = Arrays.equals(dblArray1,dblArray2);
System.out.println("Are two double arrays equal ? : " + blnResult);
    }
}

Compare Two Java float Arrays

import java.util.Arrays;  
public class CompareFloatArraysExample
{
public static void main(String[] args)
 {
float[] floatArray1 = new float[]{459.432f,348.43f,5832.327f};
float[] floatArray2 = new float[]{459.432f,348.43f,5832.327f};
boolean blnResult = Arrays.equals(floatArray1,floatArray2);
System.out.println("Are two float arrays equal ? : " + blnResult);
   }
}

Compare Two Java int Arrays

import java.util.Arrays;
public class CompareIntArraysExample
{
public static void main(String[] args)
{
int[] intArray1 = new int[]{27,78,1023};
int[] intArray2 = new int[]{27,78,1023};
boolean blnResult = Arrays.equals(intArray1,intArray2);
System.out.println("Are two int arrays equal ? : " + blnResult);
   }
}

No comments:

Post a Comment