Java long Array

It is used to store long data type values only. With the following examples you can learn how to declare long array, how to assign values to long array and how to get values from long array.

Java long Array Example
/* long Array Example */
/* Save with file name LongArray.java */

public class LongArray
{
	public static void main(String args[])
	{
		//LONG ARRAY DECLARATION
		long a[];
		//MEMORY ALLOCATION FOR LONG ARRAY
		a = new long[4];
		//ASSIGNING ELEMENTS TO LONG ARRAY
		a[0] = 100000L;
		a[1] = 300000L;
		a[2] = 400000L;
		a[3] = 786777L;
		//LONG ARRAY OUTPUT
		System.out.println();
		System.out.println("long Array Example");
		System.out.println("==================");
		System.out.println();
		for(int i=0;i<a.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + a[i]);
		}
	}
}
                        

In this example you can learn how to assign values to long array at the time of declaration.

Java long Array Example 2
/* long Array Example 2 */
/* Save with file name LongArray2.java */

public class LongArray2
{
	public static void main(String args[])
	{
		//LONG ARRAY DECLARATION
		long a[] = {100000L,300000L,400000L,786777L};
		//LONG ARRAY OUTPUT
		System.out.println();
		System.out.println("long Array Example");
		System.out.println("==================");
		System.out.println();
		for(int i=0;i<a.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + a[i]);
		}
	}
}
                        

In this example you can learn how to declare long array with other long variables.

Java long Array Example 3
/* long Array Example 3 */
/* Save with file name LongArray3.java */

public class LongArray3
{
	public static void main(String args[])
	{
		//LONG ARRAY DECLARATION
		long a[], a2; //a IS AN ARRAY a2 IS NOT AN ARRAY
		//MEMORY ALLOCATION FOR LONG ARRAY
		a = new long[4];
		//ASSIGNING ELEMENTS TO LONG ARRAY
		a[0] = 100000L;
		a[1] = 300000L;
		a[2] = 400000L;
		a[3] = 786777L;
		a2 = 222222L;
		//LONG ARRAY OUTPUT
		System.out.println();
		System.out.println("long Array Example");
		System.out.println("==================");
		System.out.println();
		System.out.println("a2 value is : "+a2);
		System.out.println();
		for(int i=0;i<a.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + a[i]);
		}
	}
}
                        

In this example you can learn how to assign long array to other long array.

Java long Array Example 4
/* long Array Example 4 */
/* Save with file name LongArray4.java */

public class LongArray4
{
	public static void main(String args[])
	{
		//LONG ARRAY DECLARATION
		long[] a, a2; //a AND a2 ARE ARRAY VARIABLES
		//MEMORY ALLOCATION FOR LONG ARRAY
		a = new long[4];
		//ASSIGNING ELEMENTS TO LONG ARRAY
		a[0] = 100000L;
		a[1] = 300000L;
		a[2] = 400000L;
		a[3] = 786777L;
		//ASSIGNING a ARRAY TO a2 ARRAY VARIABLE
		a2 = a;
		//LONG ARRAY OUTPUT
		System.out.println();
		System.out.println("long Array Example");
		System.out.println("==================");
		System.out.println();
		System.out.println("a array values");
		System.out.println();
		for(int i=0;i<a.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + a[i]);
		}
		System.out.println();
		System.out.println("a2 array values");
		for(int i=0;i<a2.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + a2[i]);
		}
	}
}