Format a string

ReturnMethodSummary
static Stringformat(Locale l, String format, Object... args)Returns a formatted string using the specified locale, format string, and arguments.
static Stringformat(String format, Object... args)Returns a formatted string using the specified format string and arguments.

public class Main {
  public static void main(String[] argv) {
    System.out.println(String.format("%4d", 0));
    System.out.println(String.format("%4d", 11));
    System.out.println(String.format("%4d", 222));
    System.out.println(String.format("%4d", 3333));
  }
}

The output:


   0
  11
 222
3333
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.