Format an object array and reference its element by index in Java
Description
The following code shows how to format an object array and reference its element by index.
Example
// w ww .j av a 2 s . co m
import java.util.Calendar;
public class Main {
public static void main(String args[]) {
Object a[] = { "String 1", "java2s.com", Calendar.getInstance() };
System.out.println(String.format("Hi %1$s at %2$s ( %3$tY %3$tm %3$te )", a));
}
}
The code above generates the following result.