java String.Format() 格式化字符串输出

输出指定格式的字符串:

Java代码 复制代码
  1. public String toString() {   
  2.     MessageFormat format = new MessageFormat(   
  3.     "bankcode: {0}, serverid: {1},date: {2}, billno: {3}, amount: {4}, merchantUrl: {5}, paypath: {6}");   
  4.     return format.format(new String[]{bankcode,serverid,date,billno,amount,merchantUrl,paypath});   
  5. }  
	public String toString() {
		MessageFormat format = new MessageFormat(
		"bankcode: {0}, serverid: {1},date: {2}, billno: {3}, amount: {4}, merchantUrl: {5}, paypath: {6}");
		return format.format(new String[]{bankcode,serverid,date,billno,amount,merchantUrl,paypath});
	}

 

输出为:

 bankcode: XXX, serverid: XXX,date: XXX, billno: XXX, amount: XXX, merchantUrl:XXX, paypath: XXX

你可能感兴趣的:(java)