字符串替换格式

import java.text.MessageFormat;

public class StrFormat {
    public static void main(String[] args) {
        String str1 = "今天你签到了吗? {0}老师提醒你,记得及时{1}哦";    
        String name = "张三";        
        String type = "签到";    
        String message = MessageFormat.format(str1, name,type);         
        System.out.println(message);     
    }
}

输出: 今天你签到了吗? 张三老师提醒你,记得及时签到哦

posted @ 2019-09-18 15:27  zhoudingzhao  阅读(331)  评论(0编辑  收藏  举报