String的format用法及MessageFormat的format的用法

 jdk 1.5里面就有 格式化 字符串

String str =  "select {0} from {1} where 1=1" ;
String c = String.format(str, "item" , "table" );
 
 
//就等于 select  item  from table where 1=1
//就是输出结果为 select  item  from table where 1=1


String str =  "select {0} from {1} where 1=1" ;
Object[] a ={ "item" , "table" };
String str = java.text.MessageFormat.format(str, a);

String str=String.format("select %s from %s where 1=1", "item","table");

猜你喜欢

转载自blog.csdn.net/gtlishujie/article/details/78123653
今日推荐