java Sting類函數

一、判斷字符串中是否包含某個字符串(字符): contains()

public class
test {
    public static void main(String[] args) {
        String x="hello world";
        boolean status=x.contains("hello");
        System.out.println(status);
    }
}

輸出結果:
true

二、判斷字符串長度: length()

public class
test {
    public static void main(String[] args) {
        String x="hello world";
        int l=x.length();
        System.out.println(l);
    }
}

三、截取字符串: substring()

public class
test {
    public static void main(String[] args) {
        String x="hello world";
        System.out.println(x.substring(0,3));
    }
}

輸出:
hel
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章