zoukankan      html  css  js  c++  java
  • 字符串用占位符拼接 String ms = MessageFormat.format("{0,number,#.##}", 3.656);

    public class Test {
    public static void main(String[] args) {
    String newContent = " private String {0}; " +
    " private boolean modify_{0} = false; " +
    " " +
    " public String {1}() '{' " +
    " return {0}; " +
    " '}' " +
    " " +
    " public void setBDCDYID(String {0}) '{' " +
    " if (this.{0} != {0}) '{' " +
    " this.{0} = {0}; " +
    " modify_{0} = true; " +
    " '}' " +
    " '}'";
    String dd = MessageFormat.format(newContent,"bdcdyic","setBdcdyid");
    System.out.println(dd);
        //特殊符号{ } 需要用左右单引号围起来 '{' '}',否则和占位符冲突
    System.out.println(MessageFormat.format("{1} '{' '}' hello {0} {1}","world","lili"));
    }

    private String id;
    public void setId(String id){
    this.id = id;
    }
    }

    第二个参数可选。

    String ms = MessageFormat.format("{0,number,#.##}", 3.656);

    若格式不匹配则报异常  如第二个参数限制为数值  但内容为 String

    参考 https://blog.csdn.net/Mr_Tony/article/details/50175447?utm_source=blogxgwz9

  • 相关阅读:
    SQL语句大全
    网页常用小技巧
    卡通时钟代码
    舒服的颜色2
    静态代码
    Hibernate工作原理
    SQl多表查询优化 高效率SQL语句
    Hibernate API、对象状态、HQL、Criteria
    MySQL 学习笔记
    intramart知识
  • 原文地址:https://www.cnblogs.com/shihx/p/13462412.html
Copyright © 2011-2022 走看看