栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java MessageFormat使用方式

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java MessageFormat使用方式

最近用到这个,通过看jdk1.8的中文文档,发现中文版翻译的乱七八糟还不如看原版
然后在IDE中看MessageFormat的 源码,大概看懂了
其意思就是,这个是用来规范格式的,把字符串按照规定的格式拼接起来

使用静态方法format()

String result = MessageFormat.format("{0} -> {1}", "Hello", "world")  // Hello -> world

放大招

package Socket_Thread.heimaLiaotian;

import java.text.MessageFormat;

public class MessageFormatDemo
{
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        String classSample = MessageFormat.format(Constant.classSample,"电脑");
        sb.append(Constant.sb0+"n");
        sb.append(classSample);
        System.out.println(sb);

    }
}

class Constant{
    public static StringBuilder sb0 = new StringBuilder("n" +
            "n" +
            "    n" +
            "    n" +
            "    n" +
            "    n" +
            "    n" +
            "    ");

    static String classSample =
            "n" +
                    "n" +
            "";

}

参考链接:
https://blog.csdn.net/m0_52571715/article/details/110356346
IDE中MessageFormat源码注释

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/693130.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号