Java - Format Specifier Justify Result

Introduction

Use '-' flag to left-justify the result.

You must use width when you specify the '-' flag

Demo

public class Main {
  public static void main(String[] args) {
    System.out.printf("'%S', '%-5S', '%.3S'%n", "Java", "Javascript", "Json");
    System.out.printf("%s %n", 2028);
    System.out.printf("%s %n", true);
    System.out.printf("%s %n", new Object());

  }//from  ww w  .  jav a 2s .  c o  m
}

Result