How to pad a String in Java?

This article shows you how to use the JDK1.5 String.format() and Apache Common Lang to left or right pad a String in Java. 1. String.format By default, the String.format() fills extra with spaces \u0020. Normally, we use replace() to pad with other chars, but it will replace the spaces in between the given string. JavaPadString1.java …

Read more

Java String Format Examples

This article shows you how to format a string in Java, via String.format(). Here is the summary. Conversion Category Description %b, %B general true of false %h, %H general hash code value of the object %s, %S general string %c, %C character unicode character %d integral decimal integer %o integral octal integer, base 8 %x, …

Read more