20165324 Java Programming Week sixth

Source: Internet
Author: User

Study number 2016-2017-2 "Java Program design" Sixth week study summary textbook Learning content Summary Eighth chapter common practical class String class
    • Constructs a String object: a constant object; string object; Reference string constant.
    • Strings are collocated: The string object uses "+" for the collocated operation, that is, the end-to-end phase.
    • Common methods of the string class
  1. public int length(): Gets the length of the string object.
  2. public boolean equals(String s): Compares whether the character sequence of the current string object is the same as the character sequence of the string object specified by the parameter S.
  3. public boolean startsWith(String s): Determines whether the prefix of the current string object's character sequence is consistent with the string object specified by the parameter.
  4. public boolean endsWith(String s): Determines whether the suffix of the current string object's character sequence is consistent with the string object specified by the parameter.
  5. public int compareTo(String s): The size of the character sequence of the string object s specified by the dictionary order with the parameter.
  6. public boolean contains(String s): Determines whether the character sequence of the current string object contains the character sequence of the parameter S.
  7. public int indexOf(String s): Returns the position of the first occurrence of the character sequence of S, starting at the 0 index position of the character sequence of the current string object. If it cannot be retrieved, it returns-1. Note: The indenxOf(String str,int startpoint) method is an overloaded method that specifies where to start the search. spaces also occupy the position of a character sequence .
  8. public int lastIndexOf(String s): Returns the position of the last occurrence of the character sequence of S, starting at the 0 index position of the character sequence of the current string object. If it cannot be retrieved, it returns-1.
  9. public String substring(int startpoint,int end): The calling method obtains a new string object, and the new string object is a sequence of characters that copies the current startpoint position to the end-1 position. You can also omit end and copy all the sequence of characters from StartPoint to the end.
    • Conversion of strings to basic data: public static String valueOf(byte/int/long/float/double n) converts the above type to a string object.
    • The string representation of the object: The object class has a public String toString() method that can be used to obtain a string representation of the object by calling the method. The returned form is: A string representation of a reference to the name of the class that created the object @ object.
    • string and character array, byte array.
    1. An example of a string and a character array illustrates:

      String s="1945年8月15日是抗战胜利日";char []a=new char[4];s.getChars(11,15,a,0);//数组a的单元依次放的字符是抗 战 胜 利
      char []c;c="睡觉".toCharArray();//数组c的单元依次放的字符是 睡 觉
    2. String and byte arrays: The construction method of the string class String (byte[],int offset,int length) , starting at offset from the beginning of the array, taking the length byte, and constructing a string object.
    3. Character encryption algorithm: If the encryption algorithm is to do the addition operation, then the decryption algorithm is the subtraction operation.
    • The substitution and decomposition of regular expressions and strings
    1. A regular expression is a sequence of characters of a string object that contains characters that have special meanings, which are called meta-characters of regular expressions.
    2. Metacharacters

    1. Qualifier

    1. String substitution: The public String replaceAll(String regex,String replacement) calling method returns a new string object, and the new string object's character sequence is a sequence of sub-characters that match all of the current object character sequences to the Regex, and the new character sequence is replaced with the character sequence of the parameter replacament, But does not affect the character sequence of the current string object.
    2. Decomposition of a sequence of characters: public String[]split(String regex) when the method is called by a string object, the regular expression specified by using the parameter regex breaks out the word in the character sequence of the current string object as a delimited tag and stores the decomposed word in a string array, such as:

      String str="1949年10月1日建国";String regex="\\D+";//匹配任何非数字字符序列String digitWord[]=str.split(regex);//digitWord[]存放的为:1949 10 1
      StringTokenizer class
Problems in teaching materials learning and the solving process

Textbook learning Problems first go to https://shimo.im/doc/1i1gldfsojIFH8Ip/to see, if others did not ask the same question, you can edit the document to add, and then copy their questions to the following:

    • Question 1:xxxxxx
    • Issue 1 Solution: XXXXXX
    • Question 2:xxxxxx
    • Issue 2 Solution: XXXXXX
    • ...
Problems in code debugging and the resolution process

Code debugging in the textbook have a problem first go to https://shimo.im/doc/1i1gldfsojIFH8Ip/to see, if others did not ask the same question, you can edit the document to add, and then copy their questions to the following:

    • Question 1:xxxxxx
    • Issue 1 Solution: XXXXXX
    • Question 2:xxxxxx
    • Issue 2 Solution: XXXXXX
    • ...
Code Hosting

Last week's summary of the wrong quiz
    • Wrong question 1 and reason, understand the situation
    • Wrong question 2 and reason, understand the situation
    • ...
Pairing and mutual evaluation reference
    • Java Learning Notes (8th Edition)

    • Java Learning Note (8th Edition) Learning Guide
    • ...

20165324 Java Programming Week sixth

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.