Common API (a) in Java

  • StringBuffer

In order to solve the village that day redundancy String string manipulation leads to improve efficiency, Java and StrinBuilder provided StringBuffer to manipulate strings, and provides a number of ways to facilitate programmers to develop.

StringBuffer and StringBuilder in both the char type variable-length string is stored as an array of space. ArrayList using the method and the like.

StringBuffer thread-safe, low efficiency.

StringBuilder thread-safe, high efficiency

  • StringBuffer constructor

StringBuffer();

Create an empty StringBuffer any space to store the character string information, an array of a char type underlying initialization character 16

StringBuffer(String str);

Create a String corresponding to the type of the supplied string StringBuffer space, the capacity of the underlying array of type char str.length + 16 based on the decision, and holds the corresponding str.

  • Add Method

append(Everything)

In StringBuffer and StringBuilder objects, additional data, and as strings.

insert(int index , Everything)

In StringBuffer and StringBuilder object at a specified index position, add anything else, and as strings

  • Check method
String toString();
The bottom of the char conversion character type array to hold the contents to the corresponding
String type string is returned
int length();
Back underlying char what an effective element type has an array.
String substring(int begin);
Acquired from the start position to the specified char the end of the active element array corresponding to the type of
String capture operation,
String substring(int begin, int end);
From the specified location begin start to end end, obtaining a corresponding character string,
Do not head to tail
int indexOf(String str);
Element specifies the character string indexing position
int lastIndexOf(String str);
The last time the specified element string where the subscript position
  • Modification method

replace(int start , int end ,String srt);

Starting at the specified position start, end to end, start "= n" end, use alternative srt

setCharAt (int index, char ch);

Ch replace the subject using the index corresponding to the specified character

  • Delete and reverse order

delete(int start , int end );

Within a specified range of characters to delete start <= n <end

deleteCharAt(int index);

Delete character at the specified target

reverse();

Reverse

 

Released eight original articles · won praise 16 · views 2232

Guess you like

Origin blog.csdn.net/weixin_42597414/article/details/104562482