Java基础_String

1. equals  , 比较字符串内容,区分大小写

		String s1 = "abc";
		String s2 = "aBc";

		System.out.println(s1.equals(s2)); --->false

 2.equalsIgnoreCase ,比较字符串内容,不区分大小写

		String s1 = "abc";
		String s2 = "aBc";

		System.out.println(s1.equalsIgnoreCase(s2)); --->true

 3.contains,字符串中是否包含且全部包含,区分大小写

		String s1 = "ABCDEF";
		String s2 = "F";
		String s3 = "f";

		System.out.println(s1.contains(s2)); --- >true
		System.out.println(s1.contains(s3)); --- >false

 4.startsWith,判断字符串开始值,区分大小写

		String s1 = "ABCDEF";

		System.out.println(s1.startsWith("A")); --->true
		System.out.println(s1.startsWith("B", 1)); --->true
		System.out.println(s1.endsWith("f")); --->false

 5.isEmpty ,判断是否为空

		String s1 = "ABCDEF";

		System.out.println(s1.isEmpty()); --- >false

6.int length()

7.char charAt(int index)  从字符串中返回 所在位置的字符

8.int indexof(int ch)  返回第一次出现的索引

9.int indexOf(String)

10.String subString(int start ,  (int end) )   截取字符串

11.getBytes 编码,把字符串转换为字符数组

		String s1 = "ABCDEF";
		byte[] arr =s1.getBytes();
		for(int i=0;i<s1.length();i++){
			System.out.println(arr[i]);
		}

 把字符数组转化为字符串

		String s2= new String(arr);
		System.out.println(s2);

12.string replace(char old ,char new )

13.string replace(String old ,String new)

14.trim()

...不一一列举了

原文地址:https://www.cnblogs.com/lyxin/p/6009703.html