package four; public class StringDemo { public static void main(String args[]) { String sour="第23届中国电影节获奖名单.txt"; String head="第"; String tail=".txt"; if(sour.startsWith(head)){ System.out.println("head is "+head); } //用于判断文件类型,很实用! if(sour.endsWith(tail)){ System.out.println("tail is "+tail); } //大小写转换 String sour2="这是一个文本,有大写 I AM EXCELLENT!有小写,hello。有混写的Hello!How are you?"; System.out.println("原来的文本:"); System.out.println(sour2); System.out.println("toLowerCase的文本:"); System.out.println(sour2.toLowerCase()); System.out.println("toUpperCase的文本:"); System.out.println(sour2.toUpperCase()); } }
控制台打印:
head is 第
tail is .txt
原来的文本:
这是一个文本,有大写 I AM EXCELLENT!有小写,hello。有混写的Hello!How are you?
toLowerCase的文本:
这是一个文本,有大写 i am excellent!有小写,hello。有混写的hello!how are you?
toUpperCase的文本:
这是一个文本,有大写 I AM EXCELLENT!有小写,HELLO。有混写的HELLO!HOW ARE YOU?