What is the use of Arrays.toString() method ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the use of Arrays.toString() method ??

23rd Mar 2017, 7:14 AM
swara
4 Answers
+ 2
This is the simplest way to print an array as a string. Remember Object.toString() not work for Arrays.
23rd Mar 2017, 10:03 AM
Bhabesh Gogoi
Bhabesh Gogoi - avatar
+ 1
double[] arr=new double [] {1,2,3,4}; System.out.println (arr.toString()); Just try to run the code. You will understand.
23rd Mar 2017, 10:08 AM
Bhabesh Gogoi
Bhabesh Gogoi - avatar
0
output is some ascii value
23rd Mar 2017, 10:15 AM
swara
0
Yeah that's what I'm saying it considers an array as a typical object and returns default string i.e a'[ representing an array, followed by a character representing the primitive data type of array followed by an Identity Hex Code. So if you wanna print an array as a string you have to use Arrays.toString() method from util class
23rd Mar 2017, 10:24 AM
Bhabesh Gogoi
Bhabesh Gogoi - avatar