12, a method in JAVA class String

1: Scanner using
    (1) appearing after JDK5 classes for keyboard input data.
    (2) construction method:
        A: System.in explain this thing.
            It is actually a standard input stream corresponding to the keyboard input
        B: Constructor
            the InputStream IS = the System.in;
            
            Scanner (the InputStream IS)
        C: common formats
            Scanner Scanner new new SC = (the System.in);
    (. 3) form the basic method :
        a: hasNextXxx () determines whether a certain type of
        B: nextXxx () return a certain type of element
    (4) to master two methods
        a: the nextInt public int ()
        B: public String nextLine ()
    (. 5) It should be noted minor problems
        a: with a Scanner object to obtain the value, and then get the string will be a small problem.
        B: Solution:
            A: a Scanner redefine the object
            b: all data are acquired character string, and then converting the corresponding
            
2: Overview of the String class and
    a series of data (1) a plurality of characters.
        In fact, it can be converted to each other and an array of characters.
    (2) construction method:
        A: public String ()
        B: public String (byte [] bytes)
        C: public String (byte [] bytes, int offset, int length)
        D: public String (char [] value)
        E: string public (char [] value, int offset, int COUNT)
        F.: public string (string Original)
        following this, though not a constructor, but the result is a string object
        G: S = string "Hello";
    (. 3) characteristics string
        a: Once assigned string can not be changed.
            Note: This refers to the contents of the string can not be changed, not a reference can not be changed.
        B: literal string object as an object created by the constructor and different
            ? String s = new String ( " hello"); and the difference between String s = "hello" in the
    interview questions (4) of the string (see the results written procedures )
        A:==和equals()
            String s1 = new String("hello");
            String s2 = new String("hello");
            System.out.println(s1 == s2);// false
            System.out.println(s1.equals(s2));// true

            String s3 = new String("hello");
            String s4 = "hello";
            System.out.println(s3 == s4);// false
            System.out.println(s3.equals(s4));// true

            String s5 = "hello";
            String s6 = "hello";
            System.out.println(s5 == s6);// true
            System.out.println(s5.equals(s6));// true
        B:字符串的拼接
            String s1 = "hello";
            String s2 = "world";
            String s3 = "helloworld";
            System.out.println(s3 == s1 + s2);// false
            System.out.println(s3.equals((s1 + s2)));// true

            System.out.println(s3 == "hello" + "world");,应该是true
            System.out.println(s3.equals("hello" + "world"));// true
    (5)字符串的功能
        A:判断功能
            boolean equals(Object obj)
            boolean equalsIgnoreCase(String str)
            boolean contains(String str)
            boolean startsWith(String str)
            boolean endsWith(String str)
            boolean isEmpty()
        B:获取功能
            int length()
            char charAt(int index)
            int indexOf(int ch)
            int indexOf(String str)
            int indexOf(int ch,int fromIndex)
            int the indexOf (String STR, int fromIndex)
            String the substring (int Start)
            String the substring (int Start, int End)
        C: conversion
            byte [] the getBytes ()
            char [] toCharArray ()
            static String valueOf (char [] CHS)
            static String valueOf (int I)
            String the toLowerCase ()
            String the toUpperCase ()
            String the concat (String STR)
        D: other features
            a: Alternatively function 
                String replace (char Old, char new new)
                String replace (String Old, String new new)
            B: go to box function
                String the TRIM ()
            c: the dictionary comparison function
                the compareTo int (String STR)
                int compareToIgnoreCase (String STR) 
    (. 6) of the string Case
        A: Analogue log User
        B: string traversal
        C: Statistics string uppercase, lowercase, and the number of numeric characters
        D: the string turn the first letter uppercase, lowercase other
        E: int array to string together into a specified format
        F: reverse a string
        G: count the number of small and medium-string big string appears

Published 18 original articles · won praise 1 · views 636

Guess you like

Origin blog.csdn.net/qq_38701007/article/details/104806798