1.代码

        //+
String arg0 = "Bob";
String arg1 = "Alice";
System.out.println("hello," + arg0 + ". I am " + arg1 + "."); //StringBuilder.append
StringBuilder builder = new StringBuilder();
builder.append("hello,");
builder.append(arg0);
builder.append(". I am ");
builder.append(arg1);
builder.append(".");
System.out.println(builder.toString()); //String.format
String formatStr = String.format("hello,%s. I am %s.", arg0, arg1);
System.out.println(formatStr); //MessageFormat.format
String formattedText = MessageFormat.format("hello,{0}. I am {1}.", arg0, arg1);
System.out.println(formattedText);

2.运行结果

hello,Bob. I am Alice.
hello,Bob. I am Alice.
hello,Bob. I am Alice.
hello,Bob. I am Alice.

java拼接字符串、格式化字符串方式的更多相关文章

  1. java.text.MessageFormat格式化字符串时的小技巧

    java.text.MessageFormat格式化字符串时的小技巧 public static void main(String[] args) throws InterruptedExceptio ...

  2. 【java初探】——格式化字符串

    String 类的静态方法format()方法用于创建格式化字符串,format()方法有两种重载形式: format(String fromat,Object...args) 该方法使用指定的格式字 ...

  3. Python 字符串格式化输出方式

    字符串格式化有两种方式:百分号方式.format方式. 其中,百分号方式比较老,而format方式是比较先进的,企图替代古老的方式,目前两者共存. 1.百分号方式 格式:%[(name)][flags ...

  4. 【java编程】格式化字符串

    String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. form ...

  5. java中实现与.net的format格式化字符串输出

    Java中的格式化字符串 System.out.println(MessageFormat.format("name={0}", "张三")); .net中的格 ...

  6. python学习6—数据类型之集合与字符串格式化

    python学习6—数据类型之集合与字符串格式化 1. 使用id()可以查看一个变量的内存地址: name = 'alex' id(name) 2. 进制转换 十进制转换为二进制等: a = 10 # ...

  7. 函数-->指定函数--->默认函数--->动态函数--> 动态参数实现字符串格式化-->lambda表达式,简单函数的表示

    #一个函数何以接受多个参数#无参数#show(): ---> 执行:show() #传入一个参数 def show(arg): print(arg) #执行 show(123) #传入两个参数 ...

  8. (十四)Python3 字符串格式化

    Python3 字符串格式化 字符串的格式化方法分为两种,分别为占位符(%)和format方式.占位符方式在Python2.x中用的比较广泛,随着Python3.x的使用越来越广,format方式使用 ...

  9. Python语法速查: 3. 字符串格式化

    返回目录 (1)简易字符串格式化 字符串属于不可变序列,只能生成新的,不能改变旧的.“字符串格式化”有点像以前C语言的sprintf,可以将若干变量代入格式化的字符串,生成一个符合要求的新字符串. 转 ...

  10. sscanf的字符串格式化用法

    sscanf()为C语言标准库函数,用于从指定字符串中读入与指定格式相符的数据.函数原型声明在stdio.h头文件中: int sscanf(const char *str, const char * ...

随机推荐

  1. 201671010436 王雪刚 实验十四 团队项目评审&课程学习总结

    一:实验名称:团队项目评审&课程学习总结 二:实验目的与要求 (1)掌握软件项目评审会流程: (2)反思总结课程学习内容. 三:实验步骤 任务一:按照团队项目结对评审名单,由项目组扮演乙方,结 ...

  2. JUnit 5.x 知识点

    出处:https://blinkfox.github.io/2018/11/15/hou-duan/java/dan-yuan-ce-shi-zhi-nan/#toc-heading-14 表面上来看 ...

  3. PHP memcache 环形队列

    <?php   /**  * PHP memcache 环形队列类  * 因业务需要只保留的队列中的Pop和Push,修改过期时间为0即永久  */ class MQueue {     pub ...

  4. c+多态的本质:编译器维护了类型信息同时插入了解释执行机制

    Calling a virtual function is slower than calling a non-virtual function for a couple of reasons: Fi ...

  5. Content-Type与MIME

    http://www.cnblogs.com/jsean/articles/1610265.html 首先,我们要了解浏览器是如何处理内容的.在浏览器中显示的内容有 HTML.有 XML.有 GIF. ...

  6. 使用cookie登录网盘账号

    ①使用Chrome浏览器登录百度网盘网页版 https://pan.baidu.com/ ②查看当前使用的cookie ③获取BDUSS 注意是全选复制,不要直接复制,会不全的. ④获取STOKEN ...

  7. Python -- seek定位文件指针位置 错误 io.UnsupportedOperation: can't do nonzero cur-relative seeks错误

    f=open("E:/test/悯农.txt",'r') str=f.read(17) print("读取的数据是:",str) position=f.tell ...

  8. ent 基本使用十 数据库迁移

    ent 提供了便捷的数据库迁移处理,我们可以直接使用生成的代码进行操作,同时代码也提供了比较全的运行选项 默认迁移处理 我们通过create 进行资源创建,默认是append-only 模式 ,以为着 ...

  9. [RN] React Native 图片懒加载库 animated-lazy-image

    React Native 图片懒加载库 animated-lazy-image 官方Github地址: https://github.com/danijelgrabez/lazy-image 使用效果 ...

  10. Git 管理篇(详细)

    新建repository 本地目录下,在命令行里新建一个代码仓库(repository) 里面只有一个README.md 命令如下: touch README.md git init 初始化repos ...