📄 stringmethods.java
字号:
/** 这个类演示字符串不同方法的用法
*/
package SG6.Example6;
public class StringMethods {
/**构造方法 */
protected StringMethods() {
}
/** 这是 main 方法
* 它演示 String 类的不同方法
* @param args 传递至 main 方法的参数
*/
public static void main(String [] args) {
String s = "Java is a " + "platform independent language";
String s1 = "Hello world";
String s2 = "Hello";
String s3 = "HELLO";
System.out.println(s);
System.out.println("index of t = " + s.indexOf('t'));
System.out.println("last index of t = " + s.lastIndexOf('t'));
System.out.println("index of(t, 10) = " + s.indexOf('t', 10));
System.out.println("last index of (t, 60) = " + s.lastIndexOf('t', 60));
System.out.println(s1.substring(6));
System.out.println(s1.substring(3, 8));
System.out.println(s2.concat("World"));
System.out.println(s2.replace('l', 'w'));
System.out.println(s3.toLowerCase());
System.out.println(s1.trim());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -