Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I expect Arrays.toString(char[] a) to return a String value similar to String.valueOf(char[] a), but it is converting whole array into a string.. For example:-
char[] a = {'a','b','c','d'}; 
System.out.println(Arrays.toString(a)); // returns  [a,b,c,d] 
Why is it not returning abcd like String.valueOf()?

What I have tried:

Using Arrays.toString() method
Posted
Updated 19-Feb-18 16:00pm
v2

1 solution

If you look at the documentation: Arrays (Java Platform SE 7 )[^] it is very explicit: it is one os a set of toString overloads that provides a quick and easy way to print the contents of an array woth each element easily identifiable, hence separated by commas.
Pass an array of integers, and it gives you [1,2,3]. Pass an array of chars, and it gives you [a, b, c]
 
Share this answer
 
Comments
Richard MacCutchan 18-Feb-18 7:48am    
If you look at the documentation
LOL
OriginalGriff 18-Feb-18 7:56am    
</sarcasm> ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900