Mega Code Archive

 
Categories / Java Tutorial / Development
 

Reordering output with argument indices

public class MainClass  {    public static void main( String args[] )     {       System.out.printf(           "Parameter list without reordering: %s %s %s %s\n",           "first", "second", "third", "fourth" );       System.out.printf(           "Parameter list after reordering: %4$s %3$s %2$s %1$s\n",           "first", "second", "third", "fourth" );          } } Parameter list without reordering: first second third fourth Parameter list after reordering: fourth third second first