Java EE Basics (12)

Source: Internet
Author: User
Tags array to string

1. Common objects (overview of scanner and method introduction)
    • Overview of A:scanner
    • Principle of construction method of B:scanner

      • Scanner (InputStream Source)
      • There is a static field under the System class:
        • public static final InputStream in; The standard input stream, which corresponds to the keyboard entry.
    • C: General method

      • Hasnextxxx () Determines if there is a next entry, where xxx can be int,double, and so on. If you need to decide whether to include the next string, you can omit xxx
      • Nextxxx () Gets the next entry. The meaning of xxx and the previous method of the same xxx, by default, scanner use spaces, carriage returns, etc. as separators
2, common objects (scanner to get the data of small problems and solutions)
    • A: Two common methods:
      • public int nextint (): Gets a value of type int
      • public string nextline (): Gets a value of type string
    • B: Case Demo
      • A: The case of getting multiple int values, multiple string values, is shown first
      • B: The problem of getting the int value first and then getting the string value
      • C: Problem Solving solution
        • The first: Gets a string after a value is first obtained and a new keyboard entry object is created.
        • The second is to get all the data first by string, then what you want, and what you convert to. (later)
3. Common objects (an overview of the String Class)
    • Overview of the A:string class

      • View the description of the string class through the API provided by the JDK

      • Can see such two words.

        • A: The string literal "abc" can also be seen as a string object.
        • B: The string is a constant, and once assigned, it cannot be changed.
4. Common objects (method of constructing the string class)
    • A: Common construction methods
      • Public String (): Empty construct
      • public string (byte[] bytes): Convert byte array to string
      • public string (byte[] bytes,int index,int length): Turns a portion of a byte array into a string
      • public string (char[] value): Convert character array to string
      • public string (char[] Value,int index,int count): Turns a part of a character array into a string
      • public string (string original): Convert string constant value to string
    • B: Case Demo
      • Demonstrates common construction methods of the String class
5. Common Objects (common interview questions for string class)
    • 1. Determine if S1 and S2 defined as string are equal
      • String s1 = "abc";
      • String s2 = "abc";
      • System.out.println (S1 = = s2);  
      • System.out.println (s1.equals (S2));  
    • 2. The following sentence creates several objects in memory?
      • String s1 = new String ("abc");
    • 3. Determine if S1 and S2 defined as string are equal
      • string s1 = new String ("abc");
      • String s2 = "abc";
      • System.out.println (S1 = = s2);?
      • System.out.println (s1.equals (S2));?
    • 4. Determine if S1 and S2 defined as string are equal
      • String s1 = "a" + "B" + "C";
      • String s2 = "abc";
      • System.out.println (S1 = = s2);?
      • System.out.println (s1.equals (S2));?
    • 5. Determine if S1 and S2 defined as string are equal
      • String s1 = "AB";
      • String s2 = "abc";
      • String s3 = s1 + "C";
      • System.out.println (s3 = = s2);
      • System.out.println (s3.equals (S2));?
6. Common objects (the judging function of string class)
    • The judgment function of A:string class
      • Boolean equals (Object obj): Compares the contents of strings for the same, case-sensitive
      • Boolean equalsignorecase (String str): Compares whether the contents of a string are the same, ignoring case
      • Boolean contains (String str): Determines whether a large string contains a small string
      • Boolean startsWith (String str): Determines whether a string begins with a specified string
      • Boolean endsWith (String str): Determines whether a string ends with a specified string
      • Boolean IsEmpty (): Determines whether the string is empty.
7. Common objects (impersonate user login)
    • A: Case Demo
      • Requirements: Simulate login, give three chances, and tip a few more times.
      • User name and password are admin
8. Common objects (Get function of String class)
    • A:string-Class Acquisition function
      • int length (): Gets the length of the string.
      • char charAt (int index): Gets the character at the specified index position
      • int indexOf (int ch): Returns the index at the first occurrence of the specified character in this string.
      • int indexOf (String str): Returns the index of the first occurrence of the specified string in this string.
      • int indexOf (int ch,int fromIndex): Returns the index at the first occurrence of the specified character from the specified position in this string.
      • int indexOf (String str,int fromIndex): Returns the index at the first occurrence of the specified string from the specified position in this string.
      • LastIndexOf
      • string substring (int start): Intercepts the string starting at the specified position, at the end of the default.
      • string substring (int start,int end): Intercepts the string from the specified position to the specified position.
9. Common objects (traversal of strings)
    • A: Case Demo
      • Requirements: Traversing strings
10_ Common objects (count different types of characters)
    • A: Case Demo
      • Requirements: Counts the number of uppercase and lowercase alphabetic characters, number of occurrences of numeric characters, and occurrences of other characters in a string.
      • [Email protected]#$%^
11. Common Objects (conversion function of String class)
    • a:string conversion Function:

      • Byte[] GetBytes (): Converts the string to a byte array.
      • Char[] ToCharArray (): Converts a string to a character array.
      • static string ValueOf (char[] CHS): Turns the character array into a string.
      • static string valueOf (int i): turns data of type int into a string.

        • Note: The valueof method of the string class can turn any type of data into a string.
      • String toLowerCase (): Turns the string into lowercase. Know

      • String toUpperCase (): Turns the string into uppercase.
      • String concat (String str): Concatenation of strings.
12. Common objects (convert characters as required) (chained programming)
    • A: Case Demo
      • Requirement: The first letter of a string is capitalized and the remainder is lowercase. (only English uppercase and lowercase characters are considered)
13. Common objects (turn arrays into strings)
    • A: Case Demo
      • Requirement: To stitch the data in an array into a string in a specified format
        • Example:
          • Int[] arr = {A-i};
        • Output Result:
          • "[1, 2, 3]"
14. Common objects (other functions of the String Class)
    • A:string replacement function and case demonstration
      • String replace (char Old,char new)
      • String Replace (string old,string new)
    • B:string to remove the string two spaces and the case demonstration
      • String Trim ()
    • C:string comparison of two strings in dictionary order and demonstration of a case
      • int CompareTo (String str) (temporarily not available)
      • int comparetoignorecase (String str) (Learn)
15. Common objects (string inversion)
    • A: Case Demo
      • Requirements: Reverse the string
        • Example: Keyboard entry "ABC"
        • Output result: "CBA"
16, common objects (in the large string to find the number of occurrences of the sequence of ideas)
    • A: Drawing Demo
      • Requirements: Count the number of occurrences of a large string of small strings
      • The large strings and small strings here can be given according to the situation themselves.
17, common objects (in a large string to find the number of occurrences of the Code implementation)
    • A: Case Demo
      • Count the number of occurrences of a large string of small strings

Java EE Basics (12)

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.