• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with bubbelsorting.  RSS feed

 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again! Got another problem with bubbelsorting. I got the result: Sorted: [I@15db9742
Can anyone here find the reason ?

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Ungerfält wrote:I got the result: Sorted: [I@15db9742
Can anyone here find the reason ?


The "[I@15db9742" means "integer array with identity hashcode of 15db9742". This value is not affected by the elements of the array. If you want to print the values of the array (which I am assuming you do), you will need to iterate through the array and print each element individually.

[EDIT] ... BTW, you already have a method that iterates through the array, but for some reason, you are not calling it.

Henry
 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, you already have a method that iterates through the array, but for some reason, you are not calling it.


But I am calling the System.out.print(bubbelSort(list.clone()) and the printList(list); - method..?
I am calling both bubbelSort-method and printList-method..? or am I not? What exatly do you mean?
 
Liutauras Vilda
Sheriff
Posts: 4918
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to print output of bubbleSort method, but there's no any return value or print statement in it.

1. To sort array, you need to use bubbleSort method.
2. To print sorted array, you need to use printList method.
 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But there´s a return list; statement at line 27? Plus I use .clone to clone the original list..?
So what exactly should I do?

I solved it. Many thanks for all your help.
line10:
correct code is:
printList(bubbelSort(list.clone()));

Hope I will understand it all logically someday to.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!