Java Arrays - toString() Method
The java.util.Arrays.toString() method returns a string representation of the contents of the specified 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).
Syntax
public static String toString(float[] a)
Parameters
a |
Specify the array whose string representation to return. |
Return Value
Returns string representation of the array.
Exception
NA.
Example:
In the example below, the java.util.Arrays.toString() method returns a string representation of the given array of floats.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating an array of floats float Arr[] = {10f, 5f, 25f, -5f, 48f}; //convert the array into a string String MyStr = Arrays.toString(Arr); //print the string System.out.println(MyStr); } }
The output of the above code will be:
[10.0, 5.0, 25.0, -5.0, 48.0]
❮ Java.util - Arrays