📄 stringmethoddemo.java
字号:
public class StringMethodDemo
{
public static void main(String[] args)
{
String str1 = "abc";
String str2 = "aab";
String str3 = "abd";
String str4 = "abc";
String str5 = "ABC";
String str6 = "abcdefgabcde";
//以上完成字符串的声明及初始化
int i = str1.compareTo(str2);
int j = str1.compareTo(str3);
int k = str1.compareTo(str4);
//以上调用String的compareTo()方法来比较字符串
System.out.println("str1 is:"+str1);
System.out.println("str2 is:"+str2);
System.out.println("str3 is:"+str3);
System.out.println("str4 is:"+str4);
System.out.println("str5 is:"+str5);
System.out.println("str6 is:"+str6);
System.out.print("The result of str1 compareTo str2 is:");
System.out.println(i);
System.out.print("The result of str1 compareTo str3 is:");
System.out.println(j);
System.out.print("The result of str1 compareTo str4 is:");
System.out.println(k);
System.out.print("The result of str1 equals str5 is:");
System.out.println(str1.equals(str5));
//调用String的equals()方法来比较字符串
System.out.print("The result of str1 equalsIgnoreCase str5 is:");
System.out.println(str1.equalsIgnoreCase(str5));
//调用String的equalsIgnoreCase()方法来比较字符串
int m = str6.indexOf((int)'d');
//调用String的indexOf()方法,返回字符'd'第一次出现的位置
System.out.println("The char \"d\" first appear position is :"+m);
int n = str6.indexOf((int)'d',4);
//调用String的indexOf()方法,返回字符'd'从第四位后,首次出现的位置
System.out.println("After 4th position The char \"d\" appear position is :"+n);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -