Java Learning Diary-4 StringBuffer class and array

Source: Internet
Author: User

First, StringBuffer class

StringBuffer is a variable character sequence.

1.1 Constructors

StringBuffer () constructs a character buffer without characters, with an initial capacity of 16 characters.

StringBuffer (int capacity) constructs a character buffer with the specified initial capacity

StringBuffer (String str) constructs a character buffer with the specified string, with an initial capacity of string capacity plus 16

Common methods of 1.2 StringBuffer class (StringBuffer no static method)

Extension of 1.2.1 StringBuffer class

Public StringBuffer append (Object obj) parameter can be int,char,string,double, etc.

Public stringbuffer Insert (int offset, data type) The data type can be an integer type, a character, a string, a Boolean type, and so on, and offset offsets indicate the index position of the insertion string

1.2.2 length and capacity of StringBuffer class objects

public int Length () returns the number of characters that the current object contains

public int Capacity () returns the number of character spaces allocated by the current object and expands to twice times the original size plus 2

1.2.3 Modification

public void Setcharat (int index,char ch)

1.2.4 Other

char charAt (int index)

void GetChars (int srcbegin, int srcend, char[] DST, int dstbegin) copy substrings to the target character array

String substring (int start)

string substring (int start, int end) intercepts substrings

Stingbuffer reverse () inverted

Second, array

2.1 Anonymous Arrays

1. An anonymous array can be assigned to an already existing array variable, regardless of the original array.

2. The type of the array variable must be consistent with the type of the anonymous array

2.2 Arrays are also objects

Length is an attribute in the array, not a method.

  

  

  

  

Java Learning Diary-4 StringBuffer class and array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.