201711671224 "Java Programming" Chapter 8 learning summary

Learning content summary

  • Stringclass
    • Java provides a special sequence of characters to deal with Stringclass
    • StringClass java.langpackage, since the java.langpackage default class is introduced, so the program can directly use Stringthe class
    • Note that the Java Stringclass declaration for the finalclass, so the user can not extend Stringclasses, namely Stringclass can not have subclasses
  • Construction Stringobjects
    • Const object
      • String constants are enclosed in double quotes target sequence of characters
      • Constant pool: constant pool of data no longer allowed to change during program execution
    • StringObjects
      • You can use Stringthe class declaration objects and create objects
      • Users can not output Stringobject reference
      • You can use an already created Stringobject creates another Stringtarget
      • Two more common method of construction
        • String (char a[])Create an array of a character with a Stringtarget
        • String(char a[],int startIndex,int count) Extracting a character array of a part of a character to create Stringobjects, the parameters startIndexand countspecify a starting position of a character extraction and the number of characters from a starting position, taken in the
      • Reference Stringconstants
        • StringConstants are objects, so you can put Stringconstant references assigned to a Stringtarget
  • String juxtaposition
    • StringObject can +be the concatenation operation, i.e., end to end, to obtain a new Stringtarget
    • If two constants concatenation operation, then still get constant, constant pool if you do not have this constant into the constant pool
  • String Common methods of the class
    • public int length(): Obtaining a character string length
    • public boolean equals(String s): Judging whether the current Stringobject is a character sequence is specified by the parameter s Stringcharacter sequence identical object
    • public boolean startsWith(String s): Judging whether the current Stringobject is a character sequence parameter specifies whether the prefix Stringcharacter sequence s of objects
    • public int compareTo(String s): Lexicographical ordering parameter s specifies the size of a character sequence comparison
    • public boolean contains(String s): StringObject calls containsthe method determines whether the current Stringobject contains a character sequence character sequence parameter s
    • public int indexOf (String str): StringObject invoke a method from the current Stringstart retrieving the index position 0 character sequence of the target position of the character sequence of str the first time, and returns the position
    • public String substring(int startpoint): String object that calls the method to obtain a new Stringtarget, the new Stringcharacter sequence to copy the current object is the Stringobject of the character sequence startpointcharacter sequence position to the last position of the character obtained. StringCalling the object substring(int start ,int end)method for obtaining a new Stringtarget, the new Stringcharacter sequence to copy the current object is the Stringobject of the character sequence startposition to the end–1character sequence of characters at the position of the obtained
    • public String trim() : Get a new Stringobject, and this new Stringcharacter sequence is the object of the current Stringsequence of characters before and after the character sequence objects removed after spaces
  • Interconversion basic string data
    • Java.lang package Integer class calls the class method which:
      public static int parseInt(String s)
      can by the string "number" characters, converted to an int
    • Use java.lang package Byte, Short, Long, Float, Double tone corresponding class by class methods string "number" characters, converted to the corresponding basic data types
    • Can String class class method
      public static String valueOf(n的类型, n), the corresponding value into a string
  • A string representation of the object
    • An object by calling the public String toString()
      get method of the object character sequence. An object call toString()method returns Stringgeneral form of a sequence of characters object is:
      a quoted string to create the object names @ object class representation
  • Character strings, byte array
    • String array of characters
      • String class constructor:
        String(char[]);;
        String(char[],int offset,int length)each string object created using all characters and character array portion of the character
      • The partial sequence of characters stored in the String object array method:
        public void getChars(int start,int end,char c[],int offset )
      • The character sequence stored in the method of the String object array:
        public char[] toCharArray()
    • Strings and bytes
      • String(byte[])It constructs a string object using the specified byte array.
        String(byte[],int offset,int length) With a portion of the specified byte array, i.e., length bytes starting at offset to take objects from an array configuration of a string starting position
      • public byte[] getBytes()Using the platform's default character encoding, storing the sequence of characters currently String object into a byte array, and returns a reference to the array.
      • public byte[] getBytes(String charsetName)Parameter specifies the character encoding, the sequence of characters currently stored in the String object into a byte array, and returns a reference to an array
    • Encryption algorithm string
      • char [] p = password.toCharArray();
  • StringTokenizer类
    • Two common constructors:
      • StringTokenizer(String s): A parser configured as a String object s. Default division marks, i.e. the space character, line feed, carriage return, Tab character, feed character as separator mark
      • StringTokenizer(String s, String delim): A parser configured as a String object s. Any sequence of characters arranged in character delim parameter is labeled as a separator
    • StringTokenizerA string parser objects referred to can use the following methods:
      • nextToken(): Get-by-language symbols (words) in the string, the string value analyzer responsible count variable is decreased by a
      • hasMoreTokens(): As long as there are language character string symbol, i.e. the value of the count variable is greater than 0, then the method returns true, false otherwise
      • countTokens(): Get the value of the count variable analyzer
  • Scannerclass
    • Scanner class using the data analysis program from the required string
  • StringBufferclass
    • StringBufferMemory entity object class can automatically change the size, easy to store a sequence of characters variable
    • Common method
      • StringBuffer append(String s): A String object s character sequence is appended to the current sequence of characters StringBuffer object, and returns the current object's reference StringBuffer
      • StringBuffer append(int n): The conversion of n int type String object, and then the String object character sequence to the sequence of characters currently StringBuffer object, and returns the current object's reference StringBuffer
      • StringBuffer append(Object o): Object The object o a character sequence appended to the current sequence of characters StringBuffer object, and returns the current object's reference StringBuffer
      • public chat charAt(int n ): To give n characters on a single character set
      • public void setCharAt(int n ,char ch): The current character position n StringBuffer object entity specified string character replacement parameter ch
      • StringBuffer insert(int index, String str) : Parameter str specified string into the location specified by the index parameter
      • public StringBuffer reverse() : The object entity characters flip
      • StringBuffer delete(int startIndex, int endIndex): Deletes a substring from the current StringBuffer object entity in the string
      • StringBuffer replace(int startIndex,int endIndex,String str): A current substrings of a string StringBuffer object entity specified by parameter string replacement str
  • DateAnd Calendarclass
    • Date class
      • Date class java.util package
      • One class constructor Date:Date nowTime=new Date();
    • Class Calendar
      • Calendar class java.util package
      • Using static method getInstance Calendar class () to initialize a calendar object:Calendar calendar= Calendar.getInstance();
  • ClassClasses and Consoleclass
    • Class class
      • Class obtained using a class and a method associated with certain Class object (className parameter specified class),
        public static Class forName(String className) throws ClassNotFoundException
        the method returns a Class object class and associated parameter className specified. If the class is in a package, className must have the package name
      • Class object obtained in the above step is called
        public Object newInstance() throws Exception,
        the method can obtain an object class className
        special note: when using Class object call newInstance () to instantiate an object of class className, class className argument constructor must Have
    • Consoleclass
      • Console cons = System.console();
  • PatternAnd Matcherclass
    • Java classes and provides Pattern Matcher class devoted to the pattern matching, the classes in the package java.util.regex
    • Build mode objects
      • Using regular expressions as parameters to give a regex called Pattern mode instance of the class pattern
      • Schema objects are regular expressions package. Pattern class class method calls the compile (String regex) Returns a schema object, wherein the parameter is a regular expression regex, referred to as mode pattern objects used
    • Get matching objects
      • Call mode object pattern matcher (CharSequence input) method returns a Matcher object matcher, referred to as a matching object

Other (perception, thinking, etc.)

no

Reference material

  • "Java Programming"

Guess you like

Origin blog.csdn.net/nemeziz/article/details/84541980