• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Code working fine, but input file is garbled on output

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am working on some code to sort different files using different sorting methods. The code is running fine and I am getting correct results from the number of comparisons and operations, but when I call yo output the file, the text is garbled and far from correct. For example, the file "10_Random" contains 20401, 11087, 62176, 70095, 20947, 20098, 90914, 53475, 51251
and 20065. However, the output after running the file for both "sorted" and "unsorted" is "[I@5ab328" gobbleygook. What is the problem here?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This says you're trying to print an array of ints: [I@5ab328.

Array classes don't override toString(), they just inherit it from Object, which prints the class name and the hashCode. You need to either use java.util.Arrays.toString(), or else just iterate over the array and print out the elements one by one.
 
Brian Mart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah yes. Thanks, I have been away from Java for a while now and completely forgot about that.
reply
    Bookmark Topic Watch Topic
  • New Topic