1: StringBuffer (Master) (1It is more common to use string concatenation, which is time consuming and memory intensive, and in order to solve this problem, Java provides a string buffer class. StringBuffer for our use. (2the construction method of the StringBuffer A:stringbuffer () B:stringbuffer (intsize) C:stringbuffer (String str) (3) Common functions of stringbuffer (Explanation of the Declaration and method of self-completion method) A: Add function B: Remove function C: Replace function D: Invert function E: intercept function (note this return value) (4StringBuffer Practice (Do it Again) a:string and stringbuffer convert strings to each other--StringBuffer Construction Method StringBuffer--String toString () method B: Concatenation of strings C: Reverses the string D: Determines whether a string is symmetric (5The interview question small detail: StringBuffer: Synchronous, data security, low efficiency. StringBuilder: Out of sync, data insecure, high efficiency. Differences between A:string,stringbuffer,stringbuilder and b:stringbuffer and Arrays?The two can be seen as a container, loaded with other data but the StringBuffer data is ultimately a string data and the array can place any type of the same data (6Note the problem: string as a formal parameter, StringBuffer as the formal parameter. 2: Array advanced and Arrays (master) (1sort A: bubble sort adjacent elements 22 comparison, large back, the first time is over, the maximum value appears at the maximum index. In the same vein, other elements can be lined up. Public Static voidBubblesort (int[] arr) { for(intx=0; x<arr.length-1; X + +) { for(inty=0; y<arr.length-1-x; y++) { if(Arr[y] > arr[y+1]) { inttemp =Arr[y]; Arr[y]= Arr[y+1]; Arr[y+1] =temp; }}}} B: Select sort 0 to index the element, and index 1 after the elements are compared, the first time is complete, the minimum value Appeared in the 0 index. In the same vein, other elements can be lined up. Public Static voidSelectsort (int[] arr) { for(intx=0; x<arr.length-1; X + +) { for(inty=x+1; y<arr.length; y++) { if(Arr[y] <Arr[x]) { inttemp =Arr[x]; ARR[X]=Arr[y]; Arr[y]=temp; } } } } (2Find A: Basic lookup for array unordered conditions Public Static intGetIndex (int[] arr,intvalue) { intindex =-1; for(intx=0; x<arr.length; X + +) { if(Arr[x] = =value) {Index=x; Break; } } returnindex; } B: Binary lookup (binary lookup) for array ordering (never sort first, find) Public Static intBinarySearch (int[] arr,intvalue) { intMin = 0; intmax = Arr.length-1; intMid = (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; } returnmid; } (3Arrays Tool Class A: 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: sort: Binary search: (4) Arrays Tool class source code parsing (5To sort the characters in a string, for example:"EDACBGF"Get Results"ABCDEFG" 3: Integer (Master) (1in order to make the basic type of data more operational, Java provides the corresponding wrapper class type for each of the basic typesbyteByte Short ShortintIntegerLongLongfloatFloatDoubleDoubleCharCharacterBooleanBoolean (2) Integer Construction method A:integer I=NewInteger (100); B:integer I=NewInteger ("100"); Note: The string must be made up of numeric characters (3) The mutual conversion of String and int a:string--intInteger.parseint ("100"); B:int--String string.valueof (100); (4other functions (understanding) of the binary conversion (5) JDK5 new features auto-boxing basic type--reference type automatic unboxing reference type--The basic type understands the following code: Integer i= 100; I+ = 200; (6) face question-data buffer pool issues between 128 and 1274: Character (Learn) (1) Character construction method Character Ch=NewCharacter (' a '); (2to master the method: (self-completion) A: Determine whether the given character is uppercase B: Determine whether the given character is lowercase C: Determine whether the given character is a numeric character D: Turn the given character into uppercase E: put the given character Turn into lowercase (3case: Number of occurrences of uppercase, lowercase, and numeric characters in the statistics string
13th Day of Java Learning