1.MessageFormat.format

import java.text.MessageFormat;

/**
* Created by SYJ on 2017/9/13.
*/
public class MainTest {
public static void main(String[] args) {
String url = "http://xxx.xxx.xxx?name={0}&age={1}";
String path = MessageFormat.format(url, "张三", 18);
System.out.println(path);//http://xxx.xxx.xxx?name=张三&age=18
}
}

2.String.format

/**
* Created by SYJ on 2017/9/13.
*/
public class MainTest {
public static void main(String[] args) {
String url = "http://xxx.xxx.xxx?name=%s&age=%d";
String path = String.format(url, "张三", 18);
System.out.println(path);//http://xxx.xxx.xxx?name=张三&age=18
}
}

String.format和MessageFormat.format的对比用法的更多相关文章

  1. MessageFormat.format用法

    用法一: package gacl.request.study; import java.io.IOException; import java.text.MessageFormat; import ...

  2. MessageFormat.format()用法

    1.java.text.Format的继承结构如下   2.MessageFormat模式 FormatElement { ArgumentIndex }:是从0开始的入参位置索引 { Argumen ...

  3. string中Insert与Format效率对比、String与List中Contains与IndexOf的效率对比

    关于string的效率,众所周知的恐怕是“+”和StringBuilder了,这些本文就不在赘述了.关于本文,请先回答以下问题(假设都是基于多次循环反复调用的情况下):1.使用Insert与Forma ...

  4. MessageFormat.format()和String.format()

    MessageFormat 提供了以与语言无关方式生成连接消息的方式.使用此方法构造向终端用户显示的消息. MessageFormat 获取一组对象,格式化这些对象,然后将格式化后的字符串插入到模式中 ...

  5. java MessageFormat.format 用法

    FormatElement: { ArgumentIndex }:是从0开始的入参位置索引. { ArgumentIndex , FormatType } { ArgumentIndex , Form ...

  6. 关于java中MessageFormat.format中单引号问题

    我们知道java中可以用MessageFormat.format来格式化字符串.这个方法在我们的实际开发中经常用到,有点类似模板,这样我们就不需要用很恶心的拼接字符串了.如下面 String s1=& ...

  7. Java魔法堂:初探MessageFormat.format和ChoiceFormat

    一.前言 刚开始从.net的转向java的时候总觉得 String.format 用得不习惯,希望格式模版会这样 {}, }$s,$s's cat.%2$s,this is %1$s's dog. . ...

  8. MessageFormat理解,MessageFormat.format(Object obj)方法

    MessageFormat.format(Object obj)方法主要用途为拼接message信息 用法: Object[] testArgs = {new String("张三" ...

  9. 7. JDK拍了拍你:字符串拼接一定记得用MessageFormat#format

    目录 ✍前言 版本约定 ✍正文 DateFormat:日期时间格式化 SimpleDateFormat NumberFormat:数字格式化 DecimalFormat 一.0和#的使用(最常见使用场 ...

随机推荐

  1. ios中广告滚动页面(uiscrollview)

    展示功能 第一步 引入 “EScrollerView.h”,EScrollerView.m"文件 用法 NSArray *imgarr=@[@"1.jpg",@" ...

  2. 使用Java调用JS

    import junit.framework.TestCase; import javax.script.ScriptEngine; import javax.script.ScriptEngineM ...

  3. memcached内存管理机制[未整理]

    memcached默认采用的是Slab Allocator的机制分配管理内存的,在此之前,内存的分配是通过对所有的记录简单地进行malloc和free来进行的,但这种方式容易造成很多内存碎片,加重操作 ...

  4. httpd: Could not reliably determine the server's fully qualified domain name(转)

    ttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for Ser ...

  5. NSAttributedString 上下标---!!!!!

    下面这段,亲试可用 /*将符号转换为上标*/ -(NSMutableAttributedString *)changeToSuperscriptForNumberSignWith:(NSString ...

  6. 《JAVA与模式》之模板模式(转载)

    模板方法在servlet中的应用:http://www.cnblogs.com/java-my-life/archive/2012/05/14/2495235.html 原文出处:http://blo ...

  7. 安装gitlab遇到的问题

    参考文章: http://www.pickysysadmin.ca/2013/03/25/how-to-install-gitlab-5-0-on-centos-6/ 一直跟着这篇文章做,还挺顺利的, ...

  8. 真正理解 git fetch, git pull 以及 FETCH_HEAD

    真正理解 git fetch, git pull 要讲清楚git fetch,git pull,必须要附加讲清楚git remote,git merge .远程repo, branch . commi ...

  9. CentOS 7安装Redis4.0.10

    cd /usr/local/src && wget http://download.redis.io/releases/redis-4.0.10.tar.gz && t ...

  10. SeqGAN 原理简述

    1. 背景GAN在之前发的文章里已经说过了,虽然现在GAN的变种越来越多,用途广泛,但是它们的对抗思想都是没有变化的.简单来说,就是在生成的过程中加入一个可以鉴别真实数据和生成数据的鉴别器,使生成器G ...