Convert a Long Array to String in Java
Declaration :
1 |
public static String toString(long[] a) |
Explanation :
Purpose | The java.util.Arrays.toString(long[]) method returns a string representation of the contents of the specified long array. The string representation consists of a list of the array’s elements enclosed in square brackets (“[]”). Adjacent elements are separated by the characters ” ” (a comma followed by a space). |
Parameters | a ===> This is the array whose string representation to return. |
Return Value | This method returns a string representation of a. |
Exception | NA |
Java Program : Example
Below example will explain java.util.Arrays.toString() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.c4learn; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { // Initialize a long array long[] arrL = new long[] { 100, 200, 300 }; // Print the long array System.out.println("The array is:"); for (long num : arrL) { System.out.println("Element Value is " + num); } System.out.println("\nString Representation :"); System.out.println(Arrays.toString(arrL)); } } |
Output of Program :
1 2 3 4 5 6 7 |
The array is: Element Value is 100 Element Value is 200 Element Value is 300 String Representation : [100, 200, 300] |