StringApi Java

public class StringApi {
    public static void main(String[] args) {
        String s = "Hello,this is the test text!";    
        System.out.println(s);

        System.out.println("char charAt(int index)");
        for (int i = 0; i < s.length(); i ++)
            System.out.print(s.charAt(i) + " ");
        System.out.println();

        System.out.println("int codePointAt(int index)");
        for (int i = 0; i < s.length(); i ++)
            System.out.print(s.codePointAt(i) + " ");
        System.out.println();

        System.out.println("int compareTo(String other)");
        String other = "Hello,this is other test text!";
        System.out.println("Compare String: " + other);
        System.out.print(s.compareTo(other));
        System.out.println();

        System.out.println("boolean equals(Object other)");
        System.out.println(s + " compare to " + other);
        System.out.print(s.equals(other));
        System.out.println();

        String other1 = "hello,this is the test text!";
        System.out.println(other1);
        System.out.println("boolean equalsIgnoreCase(String other)");
        System.out.println(s.equalsIgnoreCase(other1));
        System.out.println();

        System.out.println("boolean startsWith(String prefix)");
        System.out.println(s.startsWith("Hello"));
        System.out.println();

        System.out.println("boolean endsWith(String suffix)");
        System.out.println(s.endsWith("text!"));
        System.out.println();

        System.out.println("int indexOf(String str)");
        System.out.println(s.indexOf("this"));
        System.out.println();
        
        System.out.println("int length()");
        System.out.println(s.length());
        System.out.println();

    }    
}
posted @ 2017-03-20 20:24  Thecoollight  阅读(166)  评论(0)    收藏  举报