MessageFormat.format()和String.format()
MessageFormat 提供了以与语言无关方式生成连接消息的方式。使用此方法构造向终端用户显示的消息。
MessageFormat 获取一组对象,格式化这些对象,然后将格式化后的字符串插入到模式中的适当位置
String类的format()方法用于创建格式化的字符串以及连接多个字符串对象。
package com.java.test;
import java.text.MessageFormat;
public class TestFormat {
public static void main(String args[]){
String str="今天是{0}年{1}月{2}号,天气{3}";
String str1="今天是%s年%d月%d号,天气%s";
Object[] a={"2018","11","23","晴"};
System.out.println(MessageFormat.format(str,"2018","11","23","晴"));
System.out.println(MessageFormat.format(str,a));
System.out.println(String.format("今天是%s年%d月%d号,天气%s","2018",11,23,"晴"));
System.out.println(String.format(str1,"2018",11,23,"晴"));
}
}
结果:

MessageFormat.format()和String.format()的更多相关文章
- C# string.Format 和 String.Format 的区别
string.Format 和 String.Format ,不论是用法还是意思,都是一样的 怎么使用? 通过 占位符来替换 ,类似于 Replace 的操作 string s = string.F ...
- 点滴拾遗 - 自定义 Format 控制 String.Format 行为
点击下载示例代码 String.Format 一重载方法的签名如下 public static string Format( IFormatProvider provider, string form ...
- JS字符串格式化函数 string.format
原生JS写的仿C#的字符串format函数,在此基础上又增加了便于JS使用的字面量对象参数. 参照C#中的规则,调用的时候会检测字符串格式,如果字符串格式不规范,或者传入的参数为null或undefi ...
- String.Format in javascript
有些时候,我们确实需要在JavaScript中进行字符串替换,类似于C#中的String.Format()方法一样,只不过这种格式化替换只局限于对由'{0}','{1}','{2}'...所组成的“占 ...
- (转)使用string.Format需要注意的一个性能问题
今天,我在写C#代码时,突然发现一个最熟悉的陌生人 —— string.Format.在写C#代码的日子里,与它朝夕相伴,却没有真正去了解它.只知道在字符串比较多时,用它比用加号进行字符串连接效率更高 ...
- 异常-----Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat> or ?string(format) built-
1.错误描述 五月 27, 2014 12:07:05 上午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...
- Java中利用MessageFormat对象实现类似C# string.Format方法格式化
我们在写C#代码的时候常常会使用到string.Format("待格式化字符串{0},{1},....",参数1,参数2,...),来格式化字符串,特别是拼接字符的时候,这种方式使 ...
- String.format和MessageFormat.format的对比用法
1.MessageFormat.format import java.text.MessageFormat; /** * Created by SYJ on 2017/9/13. */ public ...
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
随机推荐
- prototype.js的Ajax对IE8兼容问题解决方案
你是否遇到过这样的问题?在使用protype.js的Ajax应用时,会出现这样的问题:只要调用了Ajax.Request,然后点该页面右键,查看“属性”就弹出“IE停止工作”的对话框,然后强制重新加载 ...
- Oracle性能优化5-索引的不足
索引的不足 1.索引开销 a.访问开销 反问集中导致热块的竞争(对最新数据的查询) 回表性能取决聚合因子 索引的访问开销,返回几条数据快,但是返回大量的数据很慢 全表扫描与全扫描 ...
- C#—Dev XtraTabControl操作总结如动态增加Tab和关闭选项卡方法等
1:显示行号 找到gridview属性 点击事件 CustomDrawRowIndicator private void gridView1_CustomDrawRowIndicator(object ...
- mount重新挂载为写模式
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system mount -o remount,rw -t rootfs rootfs /
- python实现文件下载图片视频
最近在学习爬虫,在爬取网站时很多时候是需要将图片或视频下载到本地 今天就来说说如何使用urllib将图片保存到本地 以下代码均为win7 python3.6.* 方法一(使用下载函数保存) from ...
- BZOJ1233 干草堆 - 单调队列优化DP
问题描述: 若有干个干草, 分别有各自的宽度, 要求将它们按顺序摆放, 并且每层的宽度不大于 它的下面一层 , 求最多叠几层 题解: zkw神牛证明了: 底边最短, 层数最高 证明: ...
- HTTP 1.0 Status Code Definitions
part of Hypertext Transfer Protocol -- HTTP/1.1RFC 2616 Fielding, et al. 10 Status Code Definitions ...
- Struts问题
1.struts框架的5大组件:mvc,标签库,校验框架,国际化,tiles; 2.struts的9大核心类以及与mvc对应的关系: C ActionServlet RequestProcessor ...
- java集合示例 小心重载的陷阱
package com.hra.riskprice; import com.hra.riskprice.SysEnum.Factor_Type; import org.springframework. ...
- abp项目中无法使用HttpContext.Current.Session[""]的问题
web项目Global.asax.cs中加入如下代码 public override void Init() { this.PostAuthenticateRequest += (sender, e) ...