Features of StringBuffer, Arrays, Interger, character classes in Java

Source: Internet
Author: User

1:stringbuffer (Master)
(1) Using string to do stitching, more time-consuming and also consumes memory, and this splicing operation is more common, in order to solve this problem, Java provides a
A string buffer class. StringBuffer for our use.
(2) The construction method of StringBuffer
A:stringbuffer ()
B:stringbuffer (int size)
C:stringbuffer (String str)
(3) Common features of StringBuffer
A: Add Features
Public StringBuffer Append (string str) appends the specified string to this sequence of characters.

B: Delete Feature
Public StringBuffer Delete (int start,int end) Removes the characters in the substring of this sequence.
Public stringbuffer deletecharat (int index) removes the char at the specified position of this sequence. This sequence will shorten one char.
C: Replace function
Public stringbuffer replace (int start,int end,string str) replaces characters in substrings of this sequence with the characters in the given string
D: Invert function
Public StringBuffer reverse () replaces this sequence of characters with its inverse form.
E: Intercept function (note this return value)
public string substring (int start,int end) Returns a new string containing the sequence of characters currently contained in this sequence
public string substring (int start) returns a new string containing the sequence of characters currently contained in this character sequence.
(4) StringBuffer's exercises (do it again)
A:string and StringBuffer convert each other
String--StringBuffer
Construction method
StringBuffer--String
ToString () method
B: Concatenation of strings
C: Reverse the string
D: Determine if a string is symmetrical
(5) Face test
The difference between A:string,stringbuffer,stringbuilder
The string is immutable and the Stringbuffer,stringbuilder is mutable.
StringBuffer: Synchronous, data security, low efficiency.
StringBuilder: Out of sync, data insecure, high efficiency.
What is the difference between a b:stringbuffer and an array?
Both are containers, but StringBuffer is ultimately a string, and the character array can only be loaded in any data type and can only be a uniform data type.
(6) Questions to note:
string as the formal parameter, StringBuffer as the formal parameter.
When a string is a parameter, it can be treated as a basic type and does not change the value of the argument.
When a stringbuffer is a formal parameter, the value of the corresponding argument is changed when the StringBuffer method is called, and if it is simply assigned, it does not change the value of the argument.

2: Array advanced and Arrays (master)
(1) Sort
A: Bubble sort
Adjacent elements 22 comparison, large back, the first time, the maximum value appears at the maximum index. In the same vein, other elements can be lined up.

public static void Bubblesort (int[] arr) {
for (int x=0; x<arr.length-1; x + +) {
for (int y=0; y<arr.length-1-x; y++) {
if (Arr[y] > arr[y+1]) {
int temp = Arr[y];
Arr[y] = arr[y+1];
ARR[Y+1] = temp;
}
}
}
}

B: Select sort
The elements of the 0 index, and the elements after index 1 are compared, the first is complete, the minimum value appears in the 0 index. In the same vein, other elements can be lined up.

public static void Selectsort (int[] arr) {
for (int x=0; x<arr.length-1; x + +) {
for (int y=x+1; y<arr.length; y++) {
if (Arr[y] < arr[x]) {
int temp = arr[x];
ARR[X] = Arr[y];
Arr[y] = temp;
}
}
}
}
(2) Find
A: Basic Search
In case of an unordered array

public static int GetIndex (int[] arr,int value) {
int index =-1;

for (int x=0; x<arr.length; x + +) {
if (arr[x] = = value) {
index = x;
Break
}
}

return index;
}
B: Binary search (binary find)
For an orderly array of conditions (never sort first, find)

public static int BinarySearch (int[] arr,int value) {
int min = 0;
int max = arr.length-1;
int mid = (Min+max)/2;

while (Arr[mid]! = value) {
if (Arr[mid] > value) {
max = mid-1;
}else if (Arr[mid] < value) {
Min = mid + 1;
}

if (min > Max) {
return-1;
}

Mid = (Min+max)/2;
}

return mid;
}
(3) Arrays Tool Class
A: is a tool class that operates on an array. Includes functions such as sorting and finding.
B: The method to be mastered (self-completion method)
To convert an array to a string:
Sort:
Two-point search:
(4) Source code Analysis of Arrays tool class
(5) Sort the characters in the string
Example:
"EDACBGF"
Get results
"ABCDEFG"

3:integer (Master)
(1) In order to make the basic type of data more operational, Java provides the corresponding wrapper class type for each base type
BYTE byte
Shortshort
Intinteger
Longlong
Floatfloat
Doubledouble
Charcharacter
Booleanboolean
(2) How to construct integer
A:integer i = new Integer (100);
B:integer i = new Integer ("100");
Note: The string must be made up of numeric characters
(3) Mutual conversion of string and int
a:string--INT
Integer.parseint ("100");
B:int--String
string.valueof (100);
(4) Other functions (Learn)
Binary conversion
(5) New features of JDK5
Auto-boxing base type--reference type
Auto-unpacking reference type-basic type

The following code is understood:
Integer i = 100; Automatic Boxing
i + = 200; Automatic unpacking, automatic packing
It is important to note whether the wrapper class type is NULL, so it is common to add an if decision in the code to null.
(6) Face test
When the integer type is directly assigned, the data between 128 and 127 is obtained directly from the buffer pool, and no new objects are created. Values that exceed this range will be re-new to an object. Therefore, the address of the corresponding object is different.

4:character (Learn)
(1) Character Construction method
Character ch = new Character (' a ');
(2) The method to be mastered: (self-completion)
A: Determines whether the given character is uppercase
public static Boolean isuppercase (char ch) determines whether the specified character is uppercase.
B: Determine if the given character is lowercase
public static Boolean islowercase (char ch) determines whether the specified character is a lowercase letter.
C: Determine if the given character is a numeric character
public static Boolean isdigit (char ch) determines whether the specified character is a number.
D: Turn the given character into uppercase
public static char touppercase (char ch) converts the character argument to uppercase using the case mapping information taken from the Unicodedata file.
E: Turn the given character into lowercase
public static char toLowerCase (char ch) converts the character argument to lowercase using the case mapping information taken from the Unicodedata file.
(3) Case:
Number of occurrences of uppercase, lowercase, and numeric characters in the statistics string

Features of StringBuffer, Arrays, Interger, character classes in Java

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.