Character-related operations

1.equals: When the equals method does not override the system provides, in fact, the comparison is address;
2.toString: the return of the String object representations, the default print object when a tune is actually this object toString () method
3. the essence of the character string array
4.public static void main (string [] args) {
the Person new new P1 = the Person ();
the Person new new P2 = the Person ();
System.out.println () { p1.equals (p2)} custom class needs to override the equals; basic data types provided by the system because the system does not require rewriting have been rewritten as good (String, Scanner type)
System.out.println (P1 == p2); if there is no override equals method can only compare address, the equivalent ==
after rewriting the toString method; System.out.println (p1.toString ()); print an object when the default method calls the object's toString reprinting p object is not the address of the string
System.out.println (p2.toString ());}
5.public Boolean the equals (Object obj) {
// If null is passed returns to false
IF (obj == null) {return false;}
if their transmission is returned to true
IF (the this == obj) {return to true;} this is not determined Their transfer, this means that this refers to their class; determined by determining the address
Here is polymorphic because the object is the parent class is a subclass of Person, subclass assign themselves to the parent class is polymorphic
but name here is a subclass of Person's unique attributes; object was not so downcast
if (obj instraceof Person ) {override equals method to obtain downcast instraceof determined whether to use the same type
Person p = (Person) obj // this is downcast Person p is actually Object obj; p = obj; p is obj; the method is passed over the class;
return p.name.equals (this.name) && p.age == this.age;
so p.name this.name name and class than the present; for transmission over the class can not Objec Person analogy have to turn about
the instantiated object after the equals method of Person // written, p1 and p2 who is who modulation method;
return to false;}
6.public static void main (String [] args) {
String STR = "abc"; // abc is a constant value; str variable is stored is abc address; so the value of abc is assigned but does not change the address stored str will change the
String str2 = "abc";
System.out. println ( "999"); // print is actually System.out.println ( "999" .toString ());
System.out.println (str == str2); // to true; because abc is Constant memory inside the same content in all objects call the same address;
System.out.println (str.equals (str2)); // true; from the class defined by the equals method needs to be rewritten, rewriting the system-defined class does not need because it has been written (Sting classes, class Scanner)
}
7. when converted to byte type byte character type String automatically converted according to the code table arcas: byte array values are positive away ASCII code table; negative travel Chinese code table;
8. 0-9: 48-57; AZ: 65-90; az: 97-112;
negative characters must be converted into the number of the job 2 as a character occupies two bytes rotation 9.byte String
10.char CH = {a, B , c} characters translated into strings: string str = new string (ch , 2,5); turn into the character string; ch, 2,5 from the third (because it is an array subscript 2 is the third ) 5 characters beginning turn
11. Get length: array: length attribute; set: size () method; string: length () method
12. string manipulation (string)
taken string: str.substring (); str .substring (10); from the beginning after all the subscript 10; str.substring (5,9); small scale, taken from a string of 5-9
determines what string begins; str.startsWith ( "java") ; Analyzing what end: str.endsWith ( "java")
determines whether a large string bag With a small string: str.contains ( "java");
first Analyzing small string appears in the string position: str.indexOf ( "java")
the string into bytes: byte [] by = str .getBytes ();
The string to character array: char [] ch = str.tocharArray ( );
determining whether the two are identical in content: a.equals (b); and determining whether the same content is not case sensitive: a.equalsIgonreCase (B)
13 is .StringBuffer related operations; a variable-length string is
StringBuffer sb = new StringBuffer ();
add data: sb.append (value)
deletes the specified character positions: sb.delete (0,2); 0 is started superscript, subscript 2 is the end
inserted into the specified value at the specified location: sb.insert (0, "us"); 0 is a designated index
modified or replaced at the specified location: sb.replace (2,6 "Hello ")
reverse; string is printed in turn: sb.reverse ();
to turn into a string StringBuffer you can not change the value: string str = sb.toString ();

The operation of the character associated
boolean equals (Object obj) determines the contents of the two strings are the same

boolean equalsIgnoreCase (String str) Analyzing the content of the two strings are the same, ignoring case

boolean contains (String str) determines whether the character string contains a given string

boolean startsWith (String str) determines whether the string at the beginning of a given string

boolean endsWith (String str) determines whether the end of the string given string

boolean isEmpty () determines whether the content of the string is an empty string ""

int length () Gets the length of the string

char charAt (int index) acquired on the character string specified position

String substring (int start) at the specified position, to the end of the end, the interception of the string, returns the new string

String substring (int start, int end) starting at the specified position to the end position specified, the interception of the string, returns the new string

int indexOf (int ch) acquires given character, the position of the first occurrence of the string

int indexOf (String str) obtaining a given string, the position of the first occurrence of the string

int indexOf (int ch, int fromIndex) at the specified position, acquired for a given character, the character

byte [] getBytes () converts the character string into a byte array

char [] toCharArray () converts the character string into a character array

String replace (char old, char new) in this string, given the character of the old, replaced with a new character

String replace (String old, String new) in the string, the string given the old, replaced with a new string

String trim () remove the string ends spaces, the intermediate is not removed, it returns a new string

String toLowerCase () converts the string to a lowercase string

String toUpperCase () to convert the string to uppercase string

int indexOf (String str, int fromIndex) at the specified position, acquiring a given string, the position of the first occurrence of the string

Guess you like

Origin www.cnblogs.com/hankai2735/p/11331838.html