Java - Format Specifier Argument Index

Introduction

The following sections use 's' as the conversion character for the format specifiers.

The 's' conversion formats its argument as string.

For the following code

System.out.printf("%s, %s, and %s", "Java", "Json", "Javascript");

its output:

Java, Json, and Javascript

Syntax

A format specifier can refer to an argument in three ways:

  • Ordinary indexing
  • Explicit indexing
  • Relative indexing

Demo

public class Main {
  public static void main(String[] args) {
    System.out.printf("%s, %s, and %s", "Java", "Json", "Javascript");
  }/*w ww  .  j av  a  2  s.  c om*/
}

Result