• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Converting void method to a string  RSS feed

 
Greenhorn
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!
 
Bartender
Posts: 1124
38
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.
 
Marshal
Posts: 13447
222
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.

 
Rancher
Posts: 1170
18
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
 
Evil is afoot. But this tiny ad is just an ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!