Common use of Java class

xiaoxiao2021-04-03  214

Directory 1, Integer Class 2, Float 3, Double Class 4, Character class 5, String class 6, StringTokenizer class 7, StringBuffer class 8, Random class

Integer class's method ------------------------------------------- ----------------------------------- Interger: Integer Type

1, attribute.

Static int max_value: Returns the maximum integer; static int min_value: Returns the minimum integer; Static Class Type: Returns the current type.

example:

System.out.println ("Integer.max_Value:" Integer.max_Value); result is: integer.max_value: 2147483647

2, constructor.

Integer (int value): constructor through an int value; Integer (String S): constructor through a String type;

example:

Integer i = new integer ("1234"); an Integer object having a value of 1234 is generated.

3, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. Bytevalue (): Number of integers representing byte type; 2. Int Compato (Integer Anotherinteger): Two integers. Returns 0 at equal time; returns a negative number when it is smaller; the positive number is returned.

example:

Integer i = new integer (1234); System.out.Println ("i.Compareto:" i.Compareto (New Integer (123))); result is: I.Compareto: 1

3. Int CompareTo (Object O): Compare this integer with other classes. If O is also an Integer class, perform method 2 operation; otherwise, throw the ClassCastException exception. 4. Static Integer Decode (String NM): Convert the string to an integer. 5. Double DoubleValue (): The double precision representation of this integer is obtained. 6. Boolean Equals (Object Obj): Compare two objects. 7. Float floatvalue (): A floating point representation of this integer is obtained. 8. Static Integer GetInteger (String NM): Determine the system feature value according to the specified name. 9. Static Integer GetInteger (String NM, INT VAL): The overload above. 10. Static Integer GetInteger (String NM, Integer Val): The overload above. 11. INT hascode (): Returns the hash table of this integer type. 12. INT INTVALUE (): Returns the integer represented by this integer. 13. Long LongValue (): Returns the long intensity representing this integer. 14. Static int parseint: Converts a string into an integer. S must be the time-forward system, otherwise the NumberFormATexception is thus throwing an exception. 15. Static Int Parseint: The decimal number of RADIX returns S with RADIX. The so-called base is "several enumeration." example:

String S1 = New String ("1010"); System.out.Println ("Integer.Parseint (String S, INT RADIX): Integer.Parseint (S1, 2)); result is: Integer.Parseint (String S INT RADIX: 10

16. Short ShortValue (): Returns the short integer represented by this integer. 17. Static String TobinaryString (INT I): String of the integer to the binary number. 18. Static string tohexstring (INT i): Turn the integer to a hexadecimal string. 19. Static String TOCTALSTRING (INT I): String of the integer to an octave. 20. String toString (): Convert the integer type to a string. 21. Static String Tostring (INT I): Convert the integer type to a string. Different, this is a class method. 22. Static String Tostring (INT I, INT RADIX): Converts integer i to strings in the form of a base RADIX.

example:

INT I1 = 54321; System.Out.println ("INTEGER.TOSTRING (INTEGER.TOSTRING):" Integer.Tostring (I1, 16)); Integer.Tostring (Int i, int RADIX): D431

23. Static Integer Valueof (String S): Convert strings into integer types. 24. Static Integer Valueof (String S, int RADIX): Converts the string to an integer type with a base RADIX. Float: Real Type

1, attribute.

1. Static float max_value: Returns the maximum floating point number, and is calculated from float.intBitStofloat (0x7f7fffffffff) in different hardware platforms. 2. Static float min_value: Returns the minimum floating point number and calculates float.intbitstofloat (0x1) in different hardware platforms. 3. Static float nan: Indicates the floating point number of non-numeric types, and is calculated from float.intBitStofloat (0x7fc00000) in different hardware platforms. 4. Static float negative_infinity: Returns the negative infinite floating point, and is calculated by float.intbitstofloat (0xFF800000) in different hardware platforms. 5. Static float Positive_infinity: Returns the positive infinite floating point, and is calculated by float.intBitStofloat (0x7f800000) in different hardware platforms. 6. Static Class Type: Returns the current type.

2, constructor.

FLOAT: Constructs a float object as a parameter with a Double type. FLOAT value: Construct a float object as a parameter with a float type. Float (String S): Constructs a float object as a string type as a parameter.

3, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. BYTE BYTEVALUE (): Returns the floating point number indicated by byte. 2. Static int COMPARE (Float F1, Float F2): This is a class method, compares F1 and F2. It is equivalent to New Float (F1) .Compareto (New Float (F2)). If F1 is equal to F2, returns 0; less than the relationship, return negative numbers; greater than the relationship, return positive numbers. 3. INT Compareto (Float Anotherfloat): This is an object method, and the current object is compared with Anotherfloat. The comparisons are the same as the comparative rules of 2. 4. Int CompareTo (Object O): Compare the current object with O, if o is a FLOAT class, then equivalent to 3; if it is a class, throw the ClassCastException exception. 5. Double DoubleValue (): Returns the double precision value of the floating point number. 6. Boolean Equals (Object Obj): Compares whether the current Float object is the same as the content of the OBJ. Most of the case is the value of comparing whether the value of the two FLOAT objects is equal, equivalent to the value of f1.floatvalue () == f2.floatvalue (). Different from 2, 3, 4: 6 Returns the Boolean type. 7. Static int FLOATTOINTBITS (FLOAT VALUE): Transforms it into FLOAT according to IEEE 754 and outputs its decimal value. 8. Float floatvalue (): Returns the floating point value of the floating point object. 9. Int hashcode (): Returns the hash table of the Float object. 10. INT INTVALUE (): Returns the integer value of the FLOAT object (integer part). 11. Boolean isinite (): Judging whether the Float object is endless. 12. Static Boolean isinite (FLOAT V): Similar to 11, the difference is: This is a class method, and it is determined that V is. 13. Boolean isnan (): Determines whether the FLOAT object is non-numerical. 14. Static Boolean IsNan (Float V): The function is like 13, but it is only judged. 15. Long LongValue (): Returns the length of the Float object. 16. Static Float Parsefloat (String S): Convert the string into floating point. 17. Short ShortValue (): Returns a short value of the Float object. 18. String toString (): Converts the Float object into a string. 19. Static string toString (FLOAT F): The function is the same as 18, just convert F. 20. Static Float Valueof (String S): Convert the string to floating point. example:

Float f = new Float (1237.45); Float fs = new Float ( "123.45"); Float fd = new Float (1234146865679824657987947924623724749.16416925); System.out.println ( "f.compare (fs):" f.compareTo (fs )); System.out.println ("F.Compareto (FD): F.Compareto (FD)); System.Out.println (" Float.comPare (1.23F, 3.25F): " Float.comPare (1.23f, 3.25f)); result is: F.Compare (fs): 1f.comPareto (fd): -1float.comPare (1.23F, 3.25F): -1float f = new float (1237.45); system. Out.println ("F.Equals (fs):" F.Equals (fs)); result is: F.Equals (fs): False

How to use Double class

-------------------------------------------------- ------------------------------ Double: Double Accuracy Type

1, attribute.

1. Static Double Max_Value: Returns the maximum double precision, and is calculated by Double.longBitStodouble (0x7Feffffffffffl) in different hardware platforms. 2. Static Double Min_Value: Returns the minimum double precision, and is calculated by double.longbitstodouble (0x1L) in different hardware platforms. 3. Static Double NaN: Indicates the number of non-numeric types, and is calculated by Double.longBitStodouble in different hardware platforms. 4. Static Double Negative_Infinity: Returns the number of negative infinite double precision, and is calculated by Double.longBitStodouble in different hardware platforms. 5. Static Double Positive_Infinity: Returns the number of infinite doubles, and is calculated from double.longbitstodouble in different hardware platforms. 6. Static Class Type: Returns the current type.

2, constructor.

Double (double value): Create a Double object as a Double type as a parameter. Double (String S): Create a String object as a parameter with a String type.

3, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. BYTE BYtevalue (): Returns the number of double precision indicated by bytes. 2. Static int COMPARE (Double D1, Double D2): This is a class method, compare D1 and D2. It is equivalent to New Double (D1) .Compareto (New Double (D2)). If D1 is equal to D2, return 0; less than the relationship, return negative numbers; greater than the relationship, return positive numbers. 3. Int Compareto (Double AnotherDouble): This is an object method, and the current object is compared with anotherdouble. The comparisons are the same as the comparative rules of 2. 4. Int CompareTo (Object O): Compare the current object with o, if the O is a Double class, then equivalent to 3; if it is a class, throw the ClassCastException exception. 5. Static Long DoubletolongBits (Double Value): Transform Value into Long and outputs its decimal value according to IEEE 754. 6. Double DoubleValue (): Returns the double precision value of the double precision number object. 7. Boolean Equals (Object Obj): Compares whether the current Double object is the same as the content of the OBJ. Most of the case is to compare whether the value of the two Double objects is equal, equivalent to the value of D1.DoubleValue () == D2.DouBLEVALUE (). 8. Float floatvalue (): Returns the floating point value of the floating point object. 9. INT hascode (): Returns the hash table of the Double object. 10. INT INTVALUE (): Returns the integer value of the Double object (integer part). 11. Boolean isinite (): Judging whether the Double object is endless. 12. Static Boolean Isinite (Double V): Similar to 11, the difference is: This is a class method, and it is judged that V is. 13. Boolean isnan (): Determines whether the Double object is non-value. 14. Static Boolean Isnan (Double V): The function is like 13, but it is only judged. 15. Long LongValue (): Returns the long and elevational value of the Double object. 16. Static float parsefloat (String S): Convert the string to double precision. 17. Short ShortValue (): Returns a short value of the Double object. 18. String toString (): Convert the Double object into strings. 19. Static string toString (Double F): The function is like 18, just convert F. 20. Static Double Valueof (String S): Convert the string to double precision. Example: Similar to the Float class.

How to use Character class ------------------------------------------- ----------------------------------- CHARACTER: Character Type

1, attribute.

Static int min_Radix: Returns the minimum base. Static int MAX_RADIX: Returns the maximum base. Static Char max_value: The maximum value of the character type. Static Char min_value: The minimum value of the character type. Static Class Type: Returns the current type. 2, constructor.

Character (Char Value): Constructs a Character object with a char parameter.

3, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. CHAR Charvalue (): Returns the value of the character object. 2. Int Compareto (Character Anothercharacter): Current CHARACTER object compares with ANothercharacter. Equal relationship returns 0; less than the relationship returns negative; greater than the relationship returns a positive number. 3. Int CompareTo (Object O): Compare the current object with another object. If o is a Character object, the same is true to 2; otherwise, the ClassCastException exception is thrown. 4. Static int digit (char ch, int RADIX): Returns the decimal of the value of the current character based on the base. If CHARACTER.MIN_RADIX-= RADIX <= character.max_radix, or, the CH is not a valid value in the RADIX base, returns "-1"; if the CH is "uppercase" between A to Z, return ch - ' A ' 10 value; if it is "lowercase" A to Z, return CH -' A ' 10 value.

System.out.println ("Character.min_Radix: Character.min_Radix); System.Out.println (" Character.max_Radix: Character.max_Radix); System.Out.println ("Character.digit) , 2): " Character.digit ('2', 2)); System.Out.println (" Character.digit ('7', 10): " Character.digit ('7', 10)); System.Out.println ("Character.digit ('f', 16):" Character.digit ('f', 16)); result is: character.max_radix: 2Character.max_Radix: 36character.digit ('2' , 2): -1Character.digit ('7', 10): 7Character.digit ('f', 16): 155. Boolean Equals (Object Obj): Compare with the OBJ object. Returns "True" when the OBJ is not "NULL" 6. Static Char Fordigit (int digit, int in): Determines the character represented by the current value according to the specific base. 4 The counterputing, the illegal value returns "'/ u0000'".

System.out.println ("Character.min_Radix: Character.min_Radix); System.Out.println (" Character.max_Radix: Character.max_Radix); System.Out.println ("Character.Fordigit (2, 2 : " Character.fordigit (2, 2)); System.out.Println (" Character.fordigit (7, 10): " Character.fordigit (7, 10)); System.out.Println (" Character .fordigit (15, 16): " Character.Fordigit (15, 16)); results are: character.min_Radix: 2Character.max_Radix: 36character.fordigit (2, 2): Character.Fordigit (7, 10): 7Character .fordigit (15,16): f

7. Static int GETNUMERICVALUE (Char CH): Returns the value of Character CH. 8. Static int GETTYPE (CHAR CH): Returns the type of characters. What kinds of species are specific to see Java documentation. 9. Int hashcode (): Returns the hash table of the current character. 10. Static Boolean IsDefined (Char CH): Decision Character Ch Whether the Unicode character set is defined in a clear definition. 11. Static Boolean Isdigit (Char CH): Judging whether the character CH is a number. 12. Static Boolean isidentifierignorable (CHAR CH): Judging whether the character CH is a unlicenable character in the Unicode character set. 13. Static Boolean IsisoControl (Char CH): Deconsive whether the character CH is the control character in the ISO standard. 14.Static Boolean IsJavaIdentifierPart (CHAR CH): Decluders if the character CH is part identifier in Java. 15. Static Boolean IsJavaIdentifierStart (CHAR CH): Judging whether the character CH is the first identifier in Java. 16. Static Boolean Isletter (Char CH): Judging whether the character CH is a letter. 17. Static Boolean IsletterRDigit (CHAR CH): Deconed whether the character CH is letters or numbers. 18. Static Boolean Islowercase (Char CH): Decluders if the character CH is lowercase letters. 19. Static Boolean ismirrored (CHAR C): Determine whether the character c exists in terms of the characters in the direction according to the UNICODE table. For example: "[" "]" exists in the direction of the direction, and the result is: True. 20. Static Boolean Isspacechar (Char CH): Deconsive whether the character CH is space in Unicode. 21. Static Boolean IsuPpercase (Char CH): Deconstimate whether the character CH is uppercase letters. 22. Static Boolean IsWhitespace (CHAR CH): Decluders if the character CH is empty characters in the Java definition. These include: CHAR C1 = '/ u0009'; // Level List CHAR C2 = '/ U000A'; // Removal CHAR C3 = '/ U000B'; // Vertical List CHAR C4 = '/ u000c'; // Change page char C5 = '/ u000d'; // Enter char C6 = '/ u001c'; // File Division Char C7 = '/ U001D'; // Component Segment CHAR C8 = '/ U001E'; // Record separator char C9 = '/ u001f'; // unit separator

23. Static Char TolowerCase (Char CH): Converts whether CH is lowercase. 24. String toString (): Convert the current CHARACTER object into strings. 25. Static String Tostring (Char C): This is a class method, converts C to strings. 26. Static char Touppercase (Char CH): Converting whether CH is uppercase.

System.out.println ("Character.touppercase ('q'):" Character.touppercase ('q')); System.out.Println ("Character.tolowerCasecase ('b'):" Character.tolowercase 'B')); result is: character.touppercase ('q'): QCharacter.tolowercasecase ('b'): BSTRING class How to use ---------------------------------------------------------------------- -------------------------------------------------- ------------ String: String Type This post refers to Maxlyy friends's post, special thanks here. 1, constructor.

String (): Constructs an empty string object. String (Byte [] Bytes): Conformally constructed string objects via the BYTE array. String (byte [] bytes, int offset: Starting from OFFSET, a total Length length byte constructor is constructed by a Byte array. String (char [] value): constructed string objects via a char array. String (char [] value, int offset, int count): Starting from OFFSET, a total Length length byte constructor is constructed from OFFSET. String (String Original): Constructs a copy of Original. Both, copy one Original. String (StringBuffer Buffer) Conforms string objects via StringBuffer array;

Byte [] b = {'a', 'b', 'c', 'd', 'e', ​​'f', 'g', 'h', 'I', 'J'}; char [] C = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; String Sb = New String ( b); string sb_sub = new string (b, 3, 2); string sc = new string (c); string sc_sub = new string (c, 3, 2); string sb_copy = new string (SB); system.out .println ("SB:" SB); System.out.Println ("SB_SUB:" SB_SUB); System.out.Println ("SC:" SC); System.out.Println ("SC_SUB:" SC_SUB); System.out.Println ("SB_Copy:" SB_COPY); SB: Abcdefghijsb_Sub: Desc: 0123456789SC_SUB: 34SB_COPY: ABCDEFGHIJ

2, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type. 1. CHAR Charat (int index): Take a string in a string, where the parameter index refers to the number of orders in the string. The number of strings starts from 0 to Length () - 1.

String s = new string ("AbcdefghijklmnopQrstuvwxyz"); System.out.println ("S.Charat (5): S.Charat (5)); result is: S.Charat (5): f

2. Int Compareto (String AnotherString): Current String object compares with AnotherString. The equal relationship returns 0; when it is not equal, it starts to compare from the 0 characters of the two strings, returns the first unequal character difference, the other case, the front part of the longer string is happening happens to be shorter strings Returns their length difference. 3. Int CompareTo (Object O): If o is the String object, and the 2 functionality; otherwise it will throw the ClassCastException exception.

String S1 = new string ("abcdefghijklmn"); string s2 = new string ("abcdefghij"); string s3 = new string ("abcdefghijalmn"); system.out.println ("S1.Compareto (S2):" S1 .Compareto (S2)); // Return the length difference system.out.Println ("S1.Compareto (S3): S1.Compareto (S3)); // Returns the difference result of 'k' - 'a' : S1.Compareto (S2): 4S1.Compareto (S3): 10

4. String Concat (String Str): Connect the String object with the STR. 5. Boolean ContenQuals (StringBuffer SB): Compare the String object with the StringBuffer object SB. 6. Static string copyvalueof (char [] data): 7. Static string copyvalueof (char [] data, int offset, int count): These two methods convert the char array to String, similar to one of the constructor. 8. Boolean Endswith: This string object is ending with SUFFIX.

String S1 = New String ("Abcdefghij"); String S2 = New String ("ghij"); System.out.Println ("S1.EndSwith (S2): S1.EndSwith (S2)); result is: S1 .endswith (S2): True9. Boolean equals (Object Anobject): When Anobject is not empty and returns true with the current String object; otherwise, returns false. 10. Byte [] getBytes (): Converts the String object to the BYTE array. 11. Void getChars (int srcbegin, int srcend, char [] dst, int dstbegin): This method copies the string into the character array. Among them, srcbegin is the starting position of the copy, the end position of Srcend is the copy, the string value DST is the target character array, and DstBegin is the copy start position of the target character array.

CHAR [] S1 = {'I', '', 'L', 'O', 'V', 'E', '', 'H', 'E', 'R', '!'; / / s1 = i love her! string s2 = new string ("you!"); S2.GetChars (0, 3, s1 ,7); // S1 = i love you! system.out.println (S1); To: i love you!

12. Int hashcode (): Returns the hash table of the current character. 13. INT INDEXOF (INTC): Only the first matching character position. 14. INT INDEXOF (int CH, INT fromNDEX): Find the first matching character location from fromNDEX. 15. INT INDEXOF (String Str): Only the first matching string position. 16. INT INDEXOF (String Str, Int fromNDEX): Find the first matching string position from FromIndex.

String s = new string ("Write Once, Run Anywhere!"); String ss = new string ("run"); system.out.println ("S.indexof ('R'):" S.indexof (' R ')); System.out.Println ("S.indexOf (' R ', 2):" S.indexOf (' R ', 2)); System.out.Println ("S.indexof (SS) : " S.indexof (SS)); result is: S.Indexof ('R'): 1s.indexof ('R', 2): 12s.indexof (SS): 12

17. Int LastIndexof (int CH) 19. Int LastIndexof (String Str) 20. Int LastIndexof (String Str, int fromNDEX) above four methods with 13, 14, 15, 16 Similar, different is: find the last matching content. 21. INT length (): Returns the current string length. 22. String Replace (Char Oldchar, Char Newchar): Replace the first Oldchar in the word symbol string into newchar. 23. Boolean StartSwith (String Prefix): This string object is starting with Prefix. 24. Boolean StartSwith: This String object is counted from the TOFFSET position and starts with Prefix. String s = new string ("Write Once, Run Anywhere!"); String SS = New String ("Write"); String SSS = New String ("OnCE"); System.out.Println ("S.StartSwith" : " S.StartSwith (SS)); System.out.Println (" S.StartSwith (SSS, 6): " S.StartSwith (SSS, 6)); result is: S.StartSwith (SS): Trues.StartSwith (SSS, 6): TRUE

25. String Substring (int starte): Take the start from the beginning to the end to the end. 26.String Substring (int based Substring): Take a sub-string from the start to the endIndex location from the BeginIndex location. 27. CHAR [] TOCHARARRAY (): Converts the String object to a char array. 28. String tolowercase (): Converts a string to lowercase. 29. String Touppercase (): Convert the string to uppercase.

String s = new string ("java.lang.class string"); system.out.println ("s.touppercase ():" S.TOUPPERCASE ()); system.out.println ("s.tolowercase () : " S.TolowerCase ()); result is: S.TOUPPERCASE (): java.lang.class strings.tolowercase (): java.lang.class String

30. Static string valueof (Boolean B) 31. Static string valueof (char c) 32. Static string valueof (char [] data) 33. Static string valueof (char [] data, int offset, int count) 34. Stiatic String Valueof (Double D) 35. Static String Valueof (Float F) 36. Static String Valueof (INT i) 37. Static String Valueof (long L) 38. Static String Valueof (Object Obj) More method is used to combine different types Convert to Java characters. These are all kinds of methods. How to use StringTokenizer class -------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------- StringTokenizer: String Separation Analysis Type belongs to: java.util package.

1, constructor.

1. StringTokenizer (String Str): Constructs a StringTokenizer object used to resolve the STR. The Java default separator is "space", "" "" "" "Enterprise ('/ n')", "Enter ('/ R')". 2. StringTokenizer (String Str, String Delim): Constructs a StringTokenizer object used to parse the STR and provide a specified separator. 3. StringTokenizer (String Str, String Delim, Boolean Returndelims): Constructs a StringTokenizer object used to resolve the STR and provide a specified separator, and specify whether it is returned.

2, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. INT COUNTTTOKENS (): Returns the number of times the nextToken method being called. If the constructor 1 and 2 are employed, the returned is the number of separators (Example 2). 2. Boolean HasmoreToKens (): Returns whether there is a separator. 3. Boolean HasmoreElements (): Results As 2.4. String NextToken (): Returns a string from the current location to the next separator. 5. Object nextElement (): Result with 4.6. String NextToken (String Delim): Similar to 4, returning the result with the specified separator.

example:

String S = New String ("The Java Platform Is The Ideal Platform for Network Computing"; StringTokenizer St = New StringTokenizer (s); System.out.Println ("Token Total:" St.countToKens ()); while St.haASMoreElements ()) {system.out.println (st.nextToken ());} The result is: TOKEN TOTAL: 10ThejavaplatformistheidealPlatformForNetworkComputing Example 2:

String s = new string ("the = java = platform = IS = THE = Ideal = platform = for = network = computing"); StringTokenizer St = New StringTokenizer (s, "=", true); System.out.Println "Token Total:" St.countToKens ()); while (st.hasmorelements ()) {system.out.println (st.nextToken ());} The result is: token total: 19the = java = platform = IS = THE = Ideal = platform = for = network = compuTING

How to use StringBuffer class

-------------------------------------------------- ---------------------------- StringBuffer: StringBuffer Type

Description: In practical applications, often encounter dynamic modifications to strings. At this time, the function of the String class is limited, and the StringBuffer class can complete the dynamic addition, insertion, and replacement of the string.

1, constructor.

StringBuffer (): Constructs a StringBuffer class without any character. StringBuffer:: Constructs a StringBuffer class without any characters, and its length is Length. StringBuffer: Constructs a StringBuffer class with Str for the initial value.

2, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. StringBuffer append (boolean b) 2. StringBuffer append (char [] str) 4. StringBuffer append (char [] str, int offset, int LEN) 5. StringBuffer Append (double D) 6. StringBuffer append (float f) 7. StringBuffer append (int i) 8. StringBuffer append (long l) 9. StringBuffer append (Object obj) 10. StringBuffer append (String str) 11. StringBuffer append (StringBuffer sb) above The method is to "append" elements to the string buffer, but this "element" parameter can be a string of Boolean, character, character array, double precision, floating point, integer, long-intensive number object type , String and stringbuffer class, etc. If the added characters exceed the length of the string buffer, Java will automatically expand.

String Question = New String ("1 1 ="); int answer = 3; Boolean Result = (1 1 == 3); StringBuffer SB = New StringBuffer (); sb.append (questions); sb.append ( Answer; sb.append ('/ t'); sb.append (result); system.out.println (SB); result is: 1 1 = 3 False

12. INT CAPACITY (): Returns the total space of the current StringBuffer object (string buffer), not the length of the word symbol string. 13. CHAR Charat (int index): Retrieve the characters of the quotation marks index in the current StringBuffer object. The index of the first character is "0" 14. StringBuffer delete (int start, int end): Delete the current StringBuffer object starts with the index number START to end the end of the END. 15. StringBuffer DeleteCharat (int index): Delete the character of the current StringBuffer object to index index. 16. Void EnSureCapacity: Restages the total space of the word symbol buffer. If MinImumcapacity is greater than the current total space, the new space is set: a result is minimumcapacity; another result is {"Old Space" multiply 2 plus 2}.

StringBuffer SB1 = New StringBuffer (5); StringBuffer SB2 = New StringBuffer (5); sb1.ensurecapacity (6); sb2.ensurecapacity (100); System.Out.println ("sb1.capacity:" sb1.capacity () ); System.out.println ("sb2.capacity:" sb2.capacity ()); result is: sb1.capacity: 12sb2.capacity: 100

17. Void getchars (int srcbegin, int dstbegin): Starting from the index number srcbegin of the current StringBuffer object, the substring of Srcend ends to the character array DST, and from the index number of DST Dstbegin starts. StringBuffer SB = New StringBuffer ("i love her!"); Char [] i = {',' ',' l ',' o ',' v ',' e ',' ',' Y ', 'o', 'u'}; sb.getchars (7, 10, i, 7); System.out.Println ("SB:" SB); the result is: SB: I love her!

18. INT INDEXOF (String Str): Returns the current StringBuffer object, the first position that satisfies the STR substring. 19. Int indexof (String Str, Int fromNDEX): Find from the origin of the current StringBuffer object, returns the first position that satisfies the STR substring. 20. StringBuffer INSERT (int offset, boolean b) 21. StringBuffer Insert (int offset, char c) 22. StringBuffer INSERT (int offset, char [] str) 23. StringBuffer Insert (int index, char [] str, int offset , INT LEN 24. StringBuffer Insert (int Offset, Double D) 25. StringBuffer Insert (int Offset, Float F) 26. StringBuffer Insert (int Offset, INT I) 27. StringBuffer Insert (int offset, long L) 28. StringBuffer Insert (int offset, object obj) 29. StringBuffer INSERT (int offset, string STR)

The above methods are inserted into an element in the current StringBuffer object, insert the corresponding value at the index number OFFSET. 30. Int LastIndexOf (String Str): Returns the current StringBuffer object, the last position that satisfies the STR substring. 31. INT LastIndexof (String Str, Int fromNDEX): Start looking up from the origin of the current StringBuffer object, return the last position that meets the STR substring. 32. INT Length (): Returns the length of the string in the current StringBuffer object (character buffer). Note: This method is different from Capacity (). 33. StringBuffer Replace (int Start, int end, string STR): Replace the string of the current StringBuffer object. Starting from START, replacing a STR at the end of the end of the END. 34. StringBuffer Reverse (): Turning the string.

StringBuffer SB = New StringBuffer ("0123456789); system.out.println (" sb.reverse (): " sb.reverse ()); result is: sb.reverse (): 987654321035. Void setcharat (int INDEX, CHAR CH): Set the character of the index index for CH. 36. Void SetLength: Rest setting the length of the string in the string buffer, if the NewLength is less than the current string length, the extra characters will be cut off.

StringBuffer SB = New StringBuffer ("0123456789"); sb.setlength (5); System.out.Println ("SB:" SB); result is: SB: 01234

37. String Substring (int Start): Take the current StringBuffer object, start from Start to the end of the subsidence. 38. String Substring (int start): Take the current StringBuffer object to start from START to the substring of the END. 39. String toString (): Convert the current StringBuffer object to String objects.

How to use the Random class. -------------------------------------------------- ------------------------------ Look at the needs of the Random class in the Random class today, today's method of use. .

Belong to package: java.util.random

Random: Random type

1, attribute.

no.

2, constructor.

Random (): Create a new random number generator.

Random (long seed): Create a random number generator with a seed (long integer).

3, method. Description: 1. All methods are public; 2. Writing format: [modifier] If static int parseint (String s) means: this method (PARSEINT) is Class Method, Return Type (Int), the required parameters required for the String type.

1. Protected int next (int bit): Generates the next pseudo-random number.

2. Boolean nextBoolean (): Returns the next uniform distributed Boolean value obtained from the random generator.

3. Void nextBytes: Generates a random authentication array to the specified array.

4. Double nextdouble (): Returns the next 0.0 to 1.0 double precision type value obtained from the random generator's series.

5. Float nextfloat (): Returns the next type value of 0.0 to 1.0 from the uniform distribution from the random generator.

6. Double NextGaussian (): Returns the next Gaussian distribution dual precision type value of 0.0 to 1.0 variance from the random generator.

7. Int nextint (): Returns the next value of the uniform distribution obtained from the random generator. 8. INT NEXTINT: Returns an integer value between 0 to the specified number (N) obtained from the random generator's series.

9. Long nextlong (): Returns the next uniform distribution of a uniform distribution from the random generator.

10. Void SetSeed: Sets the seeds of the random number generator as a long integer.

Description of the seed: This class object uses a 48-bit seed, and if the two instances of this class are created with the same seed, and each of them calls the method in the same order, they produce the same number. sequence.

Below the introduction of the above introduction, especially when the result of the same seed, if the object is constructed with the default constructor, they belong to the same seed.

Import java.util.random; public class testrandom {public static void main (string [] args) {random r1 = new random (50); system.out.println ("The first seed is 50 Random object"); System.out.println ("R1.NextBoolean (): / t" r1.nextBoolean ()); system.out.println ("R1.NEXTINT (): / T / T" r1.nextint ()); System.out.println ("R1.NEXTDOUBLE (): / t" r1.nextdouble ()); system.out.println ("r1.nessgaussian (): / t" r1.nextgaussian ()); system. Out.println ("-----------------------"); Random R2 = New Random (50); System.out.Println "The second seed is 50 Random object"); system.out.println ("r2.nextboolean (): / t" r2.nextBoolean ()); system.out.println ("r2.nextint (): / t / t " r2.nextint ()); system.out.println (" r2.nextdouble (): / t " r2.nextdouble ()); system.out.println (" r2.nextgaussian (): / t " r2.nextgaussian ()); system.out.println (" ----------------------- "); Random R3 = New Random (100); System.out.Println ("Random Object of Seed 100); System.out.Println (" R3.NextBoolean (): / t " R3.NextBoolean ()); System.out .println ("r3.nextint (): / t / t " r3.nextint ()); system.out.println (" r3.nessdouble (): / t " r3.nextdouble ()); system.out.println (" r3.nextgaussian (): / t " r3.nextgaussian ()); system.out.println (" The result is at a glance! ");}}

转载请注明原文地址:https://www.9cbs.com/read-131559.html

New Post(0)