java – PrintWriter. Printf and printwriter Differences between format methods
Is there any difference between the Java printwriter method printf and the format?
The document says printf is a convenient method, but if its behavior completely conforms to the format, I don't understand its convenience
Solution
As the name suggests, a convenient method - it exists only for convenience, not necessarily for function
A common situation where convenient methods exist is a method with multiple parameters, but some parameters are used in a specific way Many times, the same method will be overloaded with different parameters
Please use the following code:
public void myMethod(int value,boolean hasImportance) { // do something. } public void myMethod(int value) { myMethod(value,true); }
In the above example, the mymethod (int) method can be considered a convenient method for mymethod (int, Boolean) because it provides a default parameter for one of the parameters
In printwriter In the case of printf, it basically calls printwriter Format, but it only provides an alternative method to call the format method
Creating printf method as a convenient method may be because the name of printf method conveys the meaning of a person trying to output in format rather than just format, which does not convey the intention of a person trying to execute Output formatting