Java Data Type How to - Index Argument with argument index








Question

We would like to know how to index Argument with argument index.

Answer

import java.util.Formatter;
/* w  w w .  java  2  s  . c  o  m*/
public class MainClass {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt.format("%3$d %1$d %2$d", 10, 20, 30);

    System.out.println(fmt);
  }
}

The code above generates the following result.