Apr 22

write a java program to check two arrays are equal or not ?

This tutorial explains how to check two arrays are equal or not with help of an example.Arrays.equals() method is used to check two arrays are equal or not .

Steps to write program:

1) Create and intialize two arrays.

2) Compare two arrays by using Arrays.equals() method which takes tw arrays and returns boolean value if they are true else it returns false. Continue reading

Apr 22

How to create and initialize array in java?

Java example to create and initialize array in java

public class ArraysDemo {

	public static void main(String[] args) {

		//Creating an array

		int a[]=new int[5];

		//Adding elements to array by accessing its index

		a[0]=1;
		a[1]=2;
		a[2]=3;
		a[3]=4;
		a[4]=5;
		a[5]=6;

		//Printing the elements in array
		// length variable is used to know the size of the array
		for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
		}

	}

}