How to center a string using String.format?
I quickly hacked this up. You can now use StringUtils.center(String s, int size) in String.format. import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat; import org.junit.Test; public class TestCenter { @Test public void centersString() { assertThat(StringUtils.center(null, 0), equalTo(null)); assertThat(StringUtils.center(“foo”, 3), is(“foo”)); assertThat(StringUtils.center(“foo”, -1), is(“foo”)); assertThat(StringUtils.center(“moon”, 10), is(” moon “)); assertThat(StringUtils.center(“phone”, 14, ‘*’), is(“****phone*****”)); assertThat(StringUtils.center(“India”, 6, ‘-‘), is(“India-“)); assertThat(StringUtils.center(“Eclipse … Read more