Re-stepping on Java Road _DAY13 (Stringbuffer,array and Arrays, Integer,character)

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 functions of StringBuffer (Explanation of the Declaration and method of their own methods)
A: Add Features
B: Delete Feature
C: Replace function
D: Invert function
E: Intercept function (note this return value)
(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
Small details:
StringBuffer: Synchronous, data security, low efficiency.
StringBuilder: Out of sync, data insecure, high efficiency.
The difference between A:string,stringbuffer,stringbuilder
What is the difference between a b:stringbuffer and an array?
(6) Questions to note:
string as the formal parameter, StringBuffer as the formal parameter.

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
Short Short
int Integer
Long Long
float float
Double Double
Char Character
Boolean Boolean
(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;
i + = 200;
(6) Face test
-Data buffer pool issues between 128 and 127

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
B: Determine if the given character is lowercase
C: Determine if the given character is a numeric character
D: Turn the given character into uppercase
E: Turn the given character into lowercase
(3) Case:
Number of occurrences of uppercase, lowercase, and numeric characters in the statistics string

Re-stepping on Java Road _DAY13 (Stringbuffer,array and Arrays, Integer,character)

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.