Arrays.toString(marks) converted int value of marks to string
Title
Question
Sir/Madam, When I am repeating the program with different values of marks and then use Arrays.toString(marks) I get different values in the output. And the braces dont convert to [ ] also.I am getting wrong output.What could be the reason. This eclipse version is the latest one eclipse java 2023. What could be the possible reason?
Regards,
Swati.
Java Array-Operations 03-04 min 10-20 sec
Answers:
System.out.println(Arrays.toString(marks).replace("{", "[").replace("}", "]"));
Arrays don't override the toString() method. What you're seeing is thus the output of the default Object.toString() implementation, which contains the type of the object ([C means array of chars) followed by its hashCode.
To construct a String from a char array, use
new String(c)
System.out.println(Arrays.toString(marks).replace("{", "[").replace("}", "]"));
Login to add comment