| 11 | */ |
| 12 | public class StringDemo { |
| 13 | public static void main(String[] args) { |
| 14 | String s = "helloworld"; |
| 15 | |
| 16 | // boolean equals(Object obj):�Ƚ��ַ����������Ƿ���ͬ���ϸ����ִ�Сд |
| 17 | System.out.println("equals():" + s.equals("helloworld")); |
| 18 | System.out.println("equals():" + s.equals("HelloWorld")); |
| 19 | System.out.println("----------------------------------"); |
| 20 | |
| 21 | // boolean equalsIgnoreCase(String str):�Ƚ��ַ����������Ƿ���ͬ�������Ǵ�Сд |
| 22 | System.out.println("equalsIgnoreCase():" |
| 23 | + s.equalsIgnoreCase("helloworld")); |
| 24 | System.out.println("equalsIgnoreCase():" |
| 25 | + s.equalsIgnoreCase("HelloWorld")); |
| 26 | System.out.println("----------------------------------"); |
| 27 | |
| 28 | // boolean contains(String str):�ж��Ƿ����ָ����С�� |
| 29 | System.out.println("contains():" + s.contains("owo")); |
| 30 | System.out.println("contains():" + s.contains("hw")); |
| 31 | System.out.println("----------------------------------"); |
| 32 | |
| 33 | // boolean startsWith(String str):�ж��Ƿ���ָ�����ַ�����ͷ |
| 34 | System.out.println("startsWith():" + s.startsWith("hw")); |
| 35 | System.out.println("startsWith():" + s.startsWith("owo")); |
| 36 | System.out.println("startsWith():" + s.startsWith("h")); |
| 37 | System.out.println("----------------------------------"); |
| 38 | |
| 39 | // boolean endsWith(String str):�ж��Ƿ���ָ�����ַ�����β:�Լ���ϰ |
| 40 | |
| 41 | // boolean isEmpty():�ж��ַ����������Ƿ�Ϊ�� |
| 42 | System.out.println("isEmpty():" + s.isEmpty()); |
| 43 | // System.out.println("isEmpty():"+null.isEmpty()); |
| 44 | // //������Ϊnull��˵�������ڣ������ڣ��Ͳ��ܵ��÷��� |
| 45 | System.out.println("isEmpty():" + "".isEmpty()); |
| 46 | } |
| 47 | } |