(String[] args)
| 14 | */ |
| 15 | public class StringDemo { |
| 16 | public static void main(String[] args) { |
| 17 | String s = "helloworld"; |
| 18 | |
| 19 | // int length():�����ַ����ij��ȡ��ַ��ĸ����� |
| 20 | System.out.println("length():" + s.length()); |
| 21 | System.out.println("----------------------"); |
| 22 | |
| 23 | // char charAt(int index):�����ַ�����ָ��λ�õ��ַ��� |
| 24 | System.out.println("charAt():" + s.charAt(0)); |
| 25 | System.out.println("charAt():" + s.charAt(3)); |
| 26 | // System.out.println("charAt():" + s.charAt(13)); // |
| 27 | // StringIndexOutOfBoundsException |
| 28 | System.out.println("----------------------"); |
| 29 | |
| 30 | // int indexOf(int ch):����ָ���ַ����ַ����е�һ�γ��ֵ�λ�� |
| 31 | System.out.println("indexOf():" + s.indexOf('l')); |
| 32 | // int indexOf(int ch,int fromIndex):����ָ���ַ���ָ��λ�ÿ�ʼ���ַ����е�һ�γ��ֵ�λ�� |
| 33 | System.out.println("indexOf():" + s.indexOf('l', 4)); |
| 34 | |
| 35 | // �Լ�ѧϰ |
| 36 | // int indexOf(String str):����ָ���ַ������ַ����е�һ�γ��ֵ�λ�� |
| 37 | // int indexOf(String str,int fromIndex):����ָ���ַ�����ָ��λ�ÿ�ʼ���ַ����е�һ�γ��ֵ�λ�� |
| 38 | System.out.println("----------------------"); |
| 39 | |
| 40 | // String substring(int start):���ش�ָ��λ�ÿ�ʼ��ĩβ���Ӵ� |
| 41 | System.out.println("substring():" + s.substring(0)); |
| 42 | System.out.println("substring():" + s.substring(5)); |
| 43 | // String substring(int start,int end):���ش�ָ��λ�ÿ�ʼ��ָ��λ�ý������Ӵ� |
| 44 | // ������Ҫ�õ�owo����д |
| 45 | System.out.println("substring():" + s.substring(4, 7)); // ������ߣ��������ұ� |
| 46 | } |
| 47 | } |
nothing calls this directly
no outgoing calls
no test coverage detected