String poem = "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦";String[] split = poem.split(",");System.out.println("=======悯农======");for (int i = 0; i < split.length; i++) {System.out.println(split[i]);}System.out.println("分割后的内容");poem = "E:\\aaa\\bbb";//对于转义字符换行时,需要加特殊处理‘\’split = poem.split("\\\\");for (int i = 0; i < split.length; i++) {System.out.println(split[i]);}
//format方法String name = "Tom";int age = 10;double score = 98.3;char gender = '男';String info ="我的姓名是" + name + ",年龄是" + age + ",成绩是" + score + ",性别是" + gender + "。希望大家照顾!";System.out.println(info);String formatStr = "我的名字是%s,年龄是%d,成绩是%.2f,性别是%c,希望大家照顾!";String info2 = String.format(formatStr,name,age,score,gender);System.out.println(info2);