I have a pattern like :
String pattern = "{0},{1},{2},{3},{4},{5},{6},{7}";
I have a Array of values to get Populated in this pattern:
Object[] values = new String[8];
This Array of values is dynamic , sometimes it gets populated with full 8 allotted slots and some times it is less than that, but never more than allotted size.
Now when it is less than 8 slots(e.g), and when i format it using
MessageFormat messageFormat = new MessageFormat(pattern);
header = new StringBuffer();
messageFormat.format(values, header, null);
theirs remains those position whose substitutes are not found:
e.g:
String pattern = "{0},{1},{2},{3},{4}";
Object[] values = {"abc", "cde", "gef"};
MessageFormat messageFormat = new MessageFormat(pattern);
StringBuffer header = new StringBuffer();
System.out.println(messageFormat.format(values, header, null));
output
abc,cde,gef,{3},{4}
But what I want is those position should also be moved: As final output should be like this:
abc, cde, gef