Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert String to char[] got unexpected result  RSS feed

 
AhFai Chan
Ranch Hand
Posts: 81
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Output:

s = "ABCDEFG" a = "[C@604c9c17"
s.length() = 7 a.length = 7
s.charAt(0) = A a=[0] = A
s.charAt(1) = B a=[1] = B
s.charAt(2) = C a=[2] = C
s.charAt(3) = D a=[3] = D
s.charAt(4) = E a=[4] = E
s.charAt(5) = F a=[5] = F
s.charAt(6) = G a=[6] = G
>
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is unexpected about that? What did you expect and what was different? Have you read what the members of an array type are? They are all in the Java® Language Specification, but that can be difficult to understand. Look particularly what the toString method is.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!