Skip to content

Instantly share code, notes, and snippets.

@jarrodhroberson
Created February 17, 2014 20:12
Show Gist options
  • Save jarrodhroberson/9058162 to your computer and use it in GitHub Desktop.
Save jarrodhroberson/9058162 to your computer and use it in GitHub Desktop.
Padding Strings in Java with String.format()
public static String padRight(@Nonnull final String s, int n)
{
return String.format("%1$-" + n + "s", s);
}
public static String padLeft(@Nonnull final String s, int n)
{
return String.format("%1$" + n + "s", s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment