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 ...
随机推荐
- 如何查看mysql数据库表所使用的引擎(转载)
我们怎么样才能准确的查看mysql的存储引擎呢,下面我给大家介绍两种正确的方式. 1)正确方式一: SHOW TABLE STATUS from 数据库库名 where Name='表名' 2)mys ...
- 9.29 h5日记
1.CSS中哪些属性可以继承? font系列 text系列 color line-height 2.border-radius的值 值的顺序是左上 右上 右下 左下 则 border-radius:5 ...
- 基于kafka-net实现的可以长链接的消息生产者
今天有点时间,我就来说两句.最近接触的Kafka相关的东西要多一些,其实以前也接触过,但是在项目使用中的经验不是很多.最近公司的项目里面使用了Kafka消息中间件,由于以前的人员编写的客户端的类不是很 ...
- devexpress WinForms MVVM
WinForms MVVM This section is dedicated to the Model-View-ViewModel (MVVM) architectural pattern. Yo ...
- Oracle_高级功能(4) 数据库存储结构
数据库存储结构分为:物理存储结构和逻辑存储结构.物理结构和逻辑结构分开,对物理数据的存储不会影响对逻辑结构的访问.1.物理存储结构 数据库文件 os block2.逻辑存储结构 tablespace ...
- PAT 1016 部分A+B(15)(C++&JAVA&&Python)
1016 部分A+B(15 分) 正整数 A 的"DA(为 1 位整数)部分"定义为由 A 中所有 DA 组成的新整数 PA.例如:给定 A=3862767,D ...
- 转录组分析---Hisat2+StringTie+Ballgown使用
转录组分析---Hisat2+StringTie+Ballgown使用 (2016-10-10 08:14:45) 转载▼ 标签: 生物信息学 转录组 1.Hisat2建立基因组索引: First ...
- 网卡驱动如何设置组播MAC地址
参考资料: https://blog.csdn.net/abccheng/article/details/50465268 将网卡加入到组播组中.
- JDesktopPane JInternalFrames
通常 JInternalFrames 需要配合 JDesktopPane 一起使用. JInternalFrames 必须在 JDesktopPane 里面
- 查看CPU核数和内存
查看CPU核数 top 然后按数字键1 通过虚拟文件系统proc,直接获取CPU总数量 cat /proc/cpuinfo | grep processor 查看内存 free命令主要用于显示内存数量 ...