may i know what is the difference between the two in java? i am reading a book and it can either use both of it to display strings.
The first one writes to the stdout and the second one returns a String object.
Which to use depends on the sole purpose. If you want to display the string in the stdout (console), then use the first. If you want to get a handle to the formatted string to use further in the code, then use the second.