• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Reversing  RSS feed

 
chamini prashakthi
Ranch Hand
Posts: 127
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the output doesn't show as numbers.
It shows as [I@15db9742 .
Why is that?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chamini,
That is what arrays print by default.

Instead you can call a helper method to print out a human readable value:
 
Edwin Torres
Ranch Hand
Posts: 57
Java Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chamini-

All Java objects have a default toString() method. In your code, this method is called on Line 9 when it tries to print result. In the case of an array object, the default toString() method returns a String that is the hashcode of the array (that is what you are seeing). To print each element of the array, see Jeanne's post or use a loop to print them manually.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your method is unnecessarily complicated. It doesn't reverse the array (so it shou‍ld have a different name), but creates another array and fills it from the first. That is unnecessary; you can simply use a loop to print the array backwards.

Note that what precedes the hashcode in your printout is the name of the class and an @ sign. In this case [I is shorthand for int[].
 
chamini prashakthi
Ranch Hand
Posts: 127
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky  I got the idea .thank you .
According to my previous code it print the array object.That's the reason for print previous result.That is the thing what I got from your answer.Am I correct?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chamini prashakthi wrote:. . . . Am I correct?
Don't know. Show us your latest code and we shall know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!