InterviewSolution
Saved Bookmarks
| 1. |
Why to use Argument Index in Java? |
|
Answer» If you want to reorder OUTPUT in Java, then use Argument Index. Let’s say the output is: abc def ghi jkl mnoAnd you want to reorder and display it as: ghi jkl mno abc defFor this, use the Argument Index as shown in the FOLLOWING example: public class DEMO { public static void main(String[] args) { System.out.printf("Initial Output = %s %s %s %s %s\n", "abc", "def", "ghi", "jkl", "mno"); System.out.printf("Update output = %3$s %4$s %5$s %1$s %2$s\n", "abc", "def", "ghi", "jkl", "mno" ); } }The above example displays that we have reordered the output: Initial Output = abc def ghi jkl mno Update output = ghi jkl mno abc def |
|