How does it look like a simple getString method? Could you write me a simple example? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How does it look like a simple getString method? Could you write me a simple example?

I use out.println for this. It looks like: public void showMe() { out.println("The result is: " + getSomething() + getAnotherthing()); } ...but I heard getString method is better.

22nd May 2019, 6:46 AM
C0ldC0de
C0ldC0de - avatar
2 Answers
+ 1
if you are looking for another way to output a string, you can also use printf() var s = System.out; s.printf("The result1 is: %d (result2 is: %d)\n", getSomething(), getAnotherthing() ); or String.format() - if you want only string without output it. %d is for int values \n for end of line for details look java.util.Formatter
26th May 2019, 10:25 AM
zemiak
0
Thank you zemiak! 😀 Generally I use method with "return" when I want some kind of result. Like 5+5 return 10. String with return... For me, that was strange 😐
11th Jun 2019, 9:33 AM
C0ldC0de
C0ldC0de - avatar