Arrays and common classes

Source: Internet
Author: User
Tags stringbuffer

Two ways to declare an array:
1. Assign values when declaring:
For example: int[] Socre = {60,38,92,51};
Int[] score = new int[]{60,38,92,51};


2. Assign values after the declaration:
int[] Socre = new Int[4];

3. Note: Array declaration to tell the length of the array, subscript is starting from 0, to the length of the array-1 end

4. Declaration of two-D array: int[][] Socre = {{60,38,24}{15,28,92},{83,67,21}};
Remember the outside control line, inside the control column

5.Arryas use sort () order from small to large
CopyOf () Action array The first parameter is the array name to change, and the second parameter is the length of the array you want to modify
Fill () fills here refers to replacing all values
BinarySearch () Find array subscript position
6.String using Length () to get the string length
Split () Split string returns an array
CharAt () Gets the characters in the string
IndexOf () Gets the index of the character where the result is the INT type
SUBSTRING () passes a parameter representing the beginning of the position to the end
SUBSTRING () Two parameters represent the end of the first position to the second position-1 (remember left contains, right does not contain)
StartsWith () to determine the starting position of a string returns a Boolean value
EndsWith () to determine the end position of a string returns a Boolean value
string concatenation of strings with + on it;
7.StringBuffer StringBuffer Stitching string with append (),
StringBuffer converted to string by object name. ToString ()

Focus: The difference between the two:
Both are used to manipulate strings
string concatenation of strings, not stitching once is equivalent to creating a string object, consuming memory space
StringBuffer stitching strings with append (), only creates an object, does not consume space
StringBuilder compared to stringbuffer StringBuilder thread-safe, slow execution,
StringBuffer thread is not secure, execution speed is fast

Arrays and common classes

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.