What is the equivalent of the "setw" stream manipulator for C++ in Java?
I've been messing with the java.util.formatter class, but haven't figured this out yet?
http://www.cplusplus.com/reference/iostream/manipulators/setw/
What is the equivalent of the "setw" stream manipulator for C++ in Java?
I've been messing with the java.util.formatter class, but haven't figured this out yet?
http://www.cplusplus.com/reference/iostream/manipulators/setw/
Generally it's the number between the percent sign ('%') and the letter. ...much as you would see in the C 'printf' function.
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
formatter.format("/%10d/", 23421);
System.out.println(sb.toString());
Produces this output: / 23421/
Or you could directly use C style printf method.
System.out.printf("|%10d|",23421);
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.