A comparison of strings
Compare the encoding between the characters that make up the string (Unicode, ASCII)
Second, the creation of a series of data types
The logical structure of a string is similar to a linear table, except that the string is for a character set
For basic operations, there are differences from linear tables:
1. The linear table concerns the operation of a single element, such as finding an element, inserting a delete operation
2, string more is to find the location of the substring, get the substring of the specified position, replace the substring
Three, the storage structure of the string
As with linear tables, there are two types: sequential (with a contiguous set of address spaces), chained storage structure (a linked list with multiple characters in one node).
Pattern matching: Locating operations of substrings, often referred to as String pattern matching
1. Simple Pattern Matching: (do not use other operations < such as String interception, only using the array to achieve pattern matching)
Public classdemo01{ Public Static voidMain (string []args) {string S= "Happaaaadwdawdfadfasdfadfgadggasdgadhfjkahsdfjgasjdgfjgjhwguyfguagsyudvfvgvaghdsvfghasvdfyeyfyvayevfyuasyudgfjwebjhfve Hgvhgfvawefawefeawppy " ; String T= "Ppy" ; LongStart =System.nanotime (); System.out.println (Pusuindex (s,t)); LongEnd =System.nanotime (); System.out.println ("Code Execution Time:" + (End-start) + "ns"); } Public Static intIndexOf (String str,string t) {intm =str.length (); intn =t.length (); if(m-n<0)return-1 ; for(inti=0;i<m-n+1;i++){ if(Str.charat (i) ==t.charat (0) ) {String temp= Str.substring (i,i+N); if(Temp.equals (t)) {returnI+1 ; } } } return0 ; } Public Static intPusuindex (String s,string t) {intm =s.length (); intn =t.length (); if(m<n)return-1 ; inti = 0, j = 0 ; while(i<m&&j<N) { if(S.charat (i) = =T.charat (j)) { ++i; + + J;//J is always starting from 0}Else{i= I-j+1 ; J= 0;//J also points to the first of T } } if(j==n)returnI-n + 1 ; Else return0 ; }}
Pattern matching of string and strings