判断当前字符串是否是以给定字符串开头或者结尾的
boolean startsWith(String str);
boolean endsWith(String str);
public static void main(String[] args) {
String str = "Thinking in Java";
boolean starts = str.startsWith("Thi");
if(starts){
System.out.println("开头");
}else{
System.out.println("不是开头");
}
boolean ends = str.endsWith("Java");
if(ends){
System.out.println("结尾");
}else{
System.out.println("不是结尾");
}
}
将当前字符串中的英文部分转化为全大写或小写
String toUpperCase();
String toLowerCase();
public static void main(String[] args){
String str = "我爱Java";
String upper = str.toUpperCase();
String lower = str.toLowerCase();
System.out.println(upper);
System.out.println(lower);
Random random = new Random();
String ran = "";
for(int i= 0;i<5;i++){
int num = random.nextInt(3);
switch (num){
case 0:
char r = (char)(random.nextInt(26)+'a');
ran+=r;
break;
case 1:
char r1 = (char)(random.nextInt(26)+'A');
ran+=r1;
break;
case 2:
ran+=random.nextInt(10);
break;
}
}
System.out.println(ran);
}