可以使用 String 的 charAt 方法来判断字符串的第一个字符是否为' / ',然后使用 String 的 substring 方法去掉第一个字符。

示例代码如下:

public class Main {
    public static void main(String[] args) {
        String str = '/Hello World';
        
        if (str.charAt(0) == '/') {
            str = str.substring(1);
        }
        
        System.out.println(str);
    }
}

输出结果为:'Hello World'。

Java 判断字符串首字符是否为'/'并删除 - 代码示例

原文地址: https://www.cveoy.top/t/topic/qmYJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录