Wrote a simple version of the split string
1 Private StaticString[] Mysplit (Char[] myString,Charc) {2 //TODO Auto-generated method stubs3 intcount=0;///Statistics The number of occurrences of the split symbol4 ///First traversal, statistics the number of occurrences of the split symbol, then the returned string array should be the number of partitions +15 for(inti = 0; i < mystring.length; i++) {6 if(mystring[i]==c) {7count++;8 }9 }Ten ////The kinsoku separator is deleted. One if(mystring[0]==c) { Acount--; - } - if(mystring[mystring.length-1]==c) { thecount--; - } - ///return stirng[] -String[] Retrunstring=NewString[count+1]; + intIndex=0; -StringBuffer sbbuffer=NewStringBuffer (); + for(inti = 0; i < mystring.length; i++) { A if(i==0) { at ///First if the delimiter, directly regardless of - if(mystring[0]!=c) { - sbbuffer.append (Mystring[i]); - } - } - ///good handling in the middle in if(i!=0&&i!=mystring.length-1) { - if(mystring[i]!=c) { to sbbuffer.append (Mystring[i]); + } - Else { theretrunstring[index]=sbbuffer.tostring (); *Sbbuffer=NewStringBuffer (); $index++;Panax Notoginseng } - } the ///Tail Processing + if(i==mystring.length-1) { A if(mystring[mystring.length-1]!=c) { the sbbuffer.append (Mystring[i]); + } -retrunstring[index]=sbbuffer.tostring (); $ } $ } - returnretrunstring; -}
Testing the main function
Public Static void Main (string[] args) { String myString= "A-b EFG"; string[] SS=mysplit (Mystring.tochararray (), '); for (int i = 0; i < ss.length; i++) { = ss[i]; System.out.println (string); } }
Final Result:
A
B
Efg
Java simple split string internal implementation