This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Converting void method to a string  RSS feed

Posts: 27
Android C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there any way I can call the doBubbleSorting as a variable?
And how can I convert it to a string so I can write it to a .txt file?
Thank you!
Posts: 1088
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you  can treat values returned from a method call as variables, the problem is that doBubbleSort returns void, i.e it doesn't return anything.
Try to review your code and return the sorted list instead.
Posts: 12952
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:return the sorted list instead.

No. If someone asks you "How do I kick myself in the head?" you don't tell them to stretch and try really hard.

@OP: Don't mix concerns. That is, if you're trying to do some kind of calculation, write a method that does just the calculation. If you're trying to display something, the code that does that should be isolated from any other concern. Avoid mixing display concerns with other kinds of concerns, otherwise, your design will be too tightly coupled.

Your doBubbleSort method appears to sort its argument in place. That is, the unsorted array that you pass in to the method will be the sorted array when the method completes its work successfully. Therefore, after calling doBubbleSort, whatever is in array is going to be sorted (assuming your doBubbleSort is correct, which I have not verified).

This means you don't have to do what you're trying to do on line 6 at all.

Master Rancher
Posts: 1043
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damn Junilu, I really like your answer. High cohesion, loose copling, seperation of concerns, you almost got them all
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!