java basic type --String

char type can represent only one character. To represent a string of characters, use the String data type.

String class is a Java library of predefined classes, not a basic type is a reference type.

Simple method String object:

  • length () Returns the number of characters in a string
  • chatAt (index) Returns the specified bit character string s
  • the concat (s1) is connected to this string s1, it returns a new string     
  • toUpperCase () Returns a new string in which all capital letters    
  • the toLowerCase () Returns a new string in which all lowercase
  • trim () Returns a new string, on both sides of whitespace removed

 The connection string: String s3 = s1.concat (s2);  

                       s3 = s1 + s2;

String comparison:

  • the equals (s1) and the string is equal to s1, returns true
  • equalsIgnoreCase (s1) and the string is equal to s1, returns true, case insensitive
  • Integer compareTo (s1) returns a value greater than 0, equal to 0, less than 0
  • compareToIgnoreCase (s1) returns a value greater than 0, equal to 0, an integer less than zero, a case-insensitive comparison
  • startsWith (prefix) If the string begins with a specific prefix, returns true
  • endsWith (suffix) if specific suffix string end, returns true     
  • the contains (s1) if s1 is a substring of the character string, returns true

"==" operator: only determining whether two objects point to the same string.

equals (): determine the contents of the character variables are equal.

Obtain substring:

  • the substring (beginIndex) Returns substrings, the beginning and end of the character from the character beginIndex
  • the substring (beginIndex, endIndex) Note that all lowercase characters from beginIndex to endIndex-1 is, [,)

Character string number conversion between:

  • Converted to int type:  
  • Converted to double:
  • Converting the digital number to a string:

     

     

Guess you like

Origin www.cnblogs.com/codercql/p/12578840.html