Common string operations.

1: gets the length of the string

2: checks whether the string values are equal

3: concatenates two strings

4: Checks whether the specified string is included

5: Intercepts the string by index value

6: Finds the corresponding element in the string by index value

7: case conversion

8: Compares strings in lexicographical order

9: Finds the index value of the first occurrence of the string by specifying a character or string

packageJava Advanced 06_02_ Object-oriented;/* Common string operations. 1: get the length of the string 2:3: whether the value of the string is equal to two strings together 4: determine whether contains the specified string 5: by index values to intercept string 6: find the corresponding element in the string through index value 7: transformation of case 8: compare strings in dictionary order 9: Finds the first occurrence of the string index */ by specifying a character or string
public class StringDemo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str1="The window contains the west ridge thousand autumn snow, the door mooring dongwu Wanli ship.";
		String str2="Dark clouds are pressing down on the city, and the sun is shining.";
		String str3="The window contains snow from the West Ridge.";
		String str4="The window contains the west ridge thousand autumn snow, the door mooring dongwu Wanli ship.";
		String str5="192.168.11.20";
		String str6="Are you ok?";
		char c='snow';
		char h='black';
		System.out.println("------------- gets the length of the string:");
		int len = str1.length();
		System.out.println("Current string length:"+len);// Output: 15
		System.out.println("------------- determines whether string values are equal");
		boolean falg =str1.equals(str2);
		System.out.println("Determine if string values are equal:"+falg);// Output: false
		System.out.println("------------- concatenates two strings");
		String str = str1+str2;
		System.out.println("str"+str);// Output: the window contains xiling qianqiu snow, the door dongwu Wanli ship dark cloud pressure city city to destroy, jiaguang sun jinscale
// a concatenation method provided by the String class
		str =str1.concat(str2);
		System.out.println("String splicing method:"+str);// Output: String stitching method: window contains Xiling Qianqiu snow, door dongwu Wanli ship black cloud pressure city city to destroy, Jiaguang sun Jinscale open
		System.out.println("------------- determines whether the specified string is contained");
		boolean contains = str1.contains(str4);
		System.out.println("Judgment result:"+contains);//true
		System.out.println("------------- intercepts strings by index value");
		String substring = str1.substring(8);
		System.out.println("Truncated string:"+substring);// After the interception of the string: dongwu Wanli ship
		substring =str1.substring(0.7);
		System.out.println("Truncated string :"+substring);// Truncated string: window contains Xiling Qianqiu snow
		System.out.println("------------- finds the element corresponding to the string by index value");
		char charAt= str1.charAt(3);
		System.out.println(charAt);/ / ridge
		System.out.println("------------- case conversion");
		/* * tolowerCase(): make the uppercase smaller * * toUpperCase(): make the lowercase case uppercase * */
		System.out.println("Uppercase to lowercase:"+str6.toLowerCase());// From uppercase to lowercase: are you ok?
		System.out.println("From lowercase to uppercase:"+str6.toUpperCase());// ARE YOU OK?
		System.out.println("------------- compares strings in lexicographical order");
		// If the return value is 0, the values of the two strings are identical
		int compareTo1 = str1.compareTo(str2);
		System.out.println(compareTo1);/ / - 9274
		int compareTo2 = str1.compareTo(str4);
		System.out.println(compareTo2);/ / 0
		System.out.println("------------- finds the index of the specified character or string by the first occurrence of the character or string within the string.");
		int indexOf=str1.indexOf(h);
		System.out.println(indexOf);/ / 1}}Copy the code