Java Basic Class Learning notes (one) API Common Class (II)

Source: Internet
Author: User
Tags float double

1:stringbuffer (Master)(1) Using string concatenation, more time-consuming and also consumes memory, and this splicing operation is more common, in order to solve this problem, Java provides a string buffer class. StringBuffer for our use. (2) StringBuffer construction Method 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 function Public stringbuffer append (String str) public stringbuffer Insert (int offset,string str) B: Remove feature public Strin Gbuffer deletecharat (int index) public stringbuffer Delete (int start,int end) C: Replace function public stringbuffer replace (int Start,int end,string str) 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 //NOTE: You cannot assign the value of a string directly to StringBufferStringBuffer sb = "Hello";            Error//StringBuffer SB = s;   Error//Mode 1: By construction method StringBuffer SB = new StringBuffer (s); Mode 2: Through the Append () method StringBuffer SB2 = new StringBuffer (); StringBuffer --StringStringBuffer buffer = new StringBuffer ("Java");   String (stringbuffer buffer)//mode 1: By constructing the method string str = new string (buffer);   Mode 2: Through the ToString () method String str2 = buffer.tostring (); B: Concatenation of strings C: Reverse the string D: Determine if a string is symmetrical (5) Question #面试题 # Small details: StringBuffer: Synchronous, data security, low efficiency.  StringBuilder: Out of sync, data insecure, high efficiency. What is the difference between the A:string,stringbuffer,stringbuilder B:stringbuffer and the array? (6) Questions to note: string is passed as a parameter, and the effect and the base type are passed as arguments. (because it is a special reference type, its location in memory is not the same as other reference types)StringBuffer as the formal parameter. 2: Array advanced and Arrays (master)(1) Sort A: Bubble sortadjacent 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 SortThe 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 lookup for unordered array condition 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 ordered array of conditions (never sort first, look in) 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 classA: is a tool class that operates on an array.  Includes functions such as sorting and finding. B: The method to Master (self-completion method) convert an array to a string: public static string ToString (int[] a) sorted by: public static void sort (int[] a) binary search: public static int BinarySearch (int[] a,int key) (4) Source Code Analysis of Arrays tool class(5) Sorting the characters in the string example: "EDACBGF" to get the result "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 int Integer long float float double double  Char Character Boolean Boolean (2) integer construction method A:integer i = new Integer (100);   B:integer i = new Integer ("100"); Note: The string must be composed of numeric characters (3) the mutual conversion of string and int a:string--int Integer.parseint ("the");B:int--String string.valueof (+);(4) Other functions (understanding) conversion (5) new features of JDK5 automatic boxing basic type--reference type auto-unpacking reference type--basic type the following code is understood: Integer i = 100; i + = 200; (6) Question #面试题 #-Data buffer pool issues between 128 and 127//By looking at the source code, we know that, for data between 128 to 127, a data buffer pool, if the data is within that range, each time does not create a new space 4:character (Learn)(1) Character construction method Character ch = new Character (' a '); (2) The method to be mastered: (self-made) A: Determine whether a given character is uppercase B: Determine whether a given character is a lowercase C: Determines whether a given character is a numeric character D: turns a given character into uppercase E: turns a given character into a lowercase (3) Case: A statistic string that appears in uppercase, lowercase, and numeric characters Number

Java Basic Class Learning notes (one) API Common Class (II)

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.