• 코드:
 
1
public class prog {
2
    public static void main(String[] args) {
3
        String str = new String("abcd");
4
        System.out.println("원본 문자열 : " + str);
5
        
6
        System.out.println(str.compareTo("bcef"));
7
        System.out.println(str.compareTo("abcd"));
8
        
9
        System.out.println(str.compareTo("Abcd"));
10
        System.out.println(str.compareToIgnoreCase("Abcd"));
11
        System.out.println("compareTo() 메소드 호출 후 원본 문자열 : " + str);
12
    }
13
}
표준입력 & 실행옵션