Common methods of String class in Java

  The String class provides many methods for processing strings, such as getting the length of the string, intercepting the string, converting the string to uppercase or lowercase, splitting the string, etc. The following are commonly used methods for processing strings:

  length(): The return value is int, which returns the length of the current string;

  indexOf(int char): The return value is int type, find the first occurrence of the char character in the string;

  indexOf(String str): The return value is int type, find the position where str substring appears for the first time in the string;

  lastIndexOf(int char): The return value is int type, find the position of the last occurrence of char character in the string;

  lastIndexOf(String str): The return value is int type, find the position of the last occurrence of str substring in the string;

  substring(int beinIndex): The return value is String, and the substring from the beginningIndex position to the end is obtained;

  substring(int beinIndex, int endIndex): The return value is String, and the substring from the beginIndex position to the endIndex is obtained;

  trim(): The return value is String type, and returns the string with the leading and trailing spaces removed;

  equals(Object obj): The return value is boolean, compare the string with the specified object, and return true or false;

  oLowerCase(): The return value is of type String, which converts the string to lowercase;

  toUpperCase(): The return value is String, which converts the string to uppercase;

  charAt(int index): The return value is char type, and the character at the specified position in the string is obtained;

  split(String regex, int limit): The return value is String[], which splits the string into substrings;

  getBytes(): The return value is of type byte[], which converts the string to byte.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325151013&siteId=291194637