直接上实例:
String []weather = {
"2020",
"11",
"12",
"五",
"晴",
"27",
};
String template = "%s年%-2s月%2s日|星期%s|天气%s|%s℃";//设置模板,其中数字2为占位符,内容不足2位使用空格补齐,在数字前加上减号代表左对齐,否则为右对齐
String row = String.format(template,weather);
System.out.println(row);//输出为:2020年11月12日|星期五|天气晴|27℃