Win a copy of Spring in Action (5th edition) this week in the Spring 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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!
 
Ranch Foreman
Posts: 1024
24
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.
 
Sheriff
Posts: 12747
210
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: 511
11
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!