API: Application Program Interface, application programming interface. In layman’s terms, it is a set of class libraries provided by the system.
Find the lang package in the API documentation, which contains many commonly used classes.
1.Basic type
Basic data type Class type
byte Byte
short Short
int Integer
long
boolean Boolean
These eight categories Types have their own attributes and methods respectively. Let’s give an example:
Integer class
Attributes:
Maximum value of int: Integer.MAX_VALUE
Minimum value of int: Integer.MIN_VALUE
Method:
Convert an integer to a string: Integer.toString(100);
Convert an integer to a string corresponding to the base system: Integer.toString(a,2);
Convert a purely numeric string to an integer: Integer.valueOf ("12345");
Convert a pure numeric string to an integer: Integer.valueOf("1100011",2);
Convert a pure numeric string to an integer: Integer.parseInt("12345");
Convert a purely numeric string to an integer: Integer.parseInt("1100011",2);
Convert an integer to binary: Integer.toBinaryString(a);
Convert an integer to hexadecimal: Integer.toHexString(a);
Convert an integer to octal: Integer.toOctalString(a);
Example:
1. Convert the positive integer 90 to binary, octal, hexadecimal
java code uPublic class commonly used category { Public Static Void Main (String [] ARGS) { int a = 90; String s = Integer.tobinaryString (a); // A Convert to binary System.out.println(s); println(s1); String s2=Integer.toHexString(a);//Convert a to hexadecimal System.out.println(s2); String s3=Integer.toString(a, 2);//Convert a is output as a string in binary form.Attribute: E
PI
Method: Math .abs(t); //The absolute value of a
Math.max(a,b); //The maximum value of a
Math.min(a,b); //The minimum value of a
Math. pow(a,b); //The b power of a
Math.sqrt(a); //The square root of a
Math.random(); //Randomly obtain a number between 0.0 and 1.0
3. System class
attributes: System.err.println();
System.out.println();
System.in
method: System.exit(0); .
System.currentTimeMillis(); //Get the current system time
System.arraycopy(Object src,int srcPos,Object dest,int destPos, int length); //Copy the array
Parameter 1: Source array
parameter 2: The starting subscript position in the source array
Parameter 3: The target array
Parameter 4: The starting subscript position in the target data
制 Parameter 5: Number of copies Example: int [] a = {1, 2, 3, 4, 5}; int [] b = new int [10]; , 1, b, 4, 3); Java code import java.util.Scanner; public class Common class 1 { public static void main(String[]args ) { Er n Scanner sc = New Scanner (System.in); System.out.println ("Please enter the division and divide number:); int a = sc.nextint (); int b = sc.nextInt(); int[]array1={2,9,11,5,8,3}; int[]array2=new int[6]; if(b==0){ System.err.println ("The dividend cannot be 0");System.out.println(c);
long x=System.currentTimeMillis();
System.out.println("The current time is "+x);
System.arraycopy(array1, 1, array2, 2, 4);
System. out.print("The data in array array2 is ");
;
There are several different sets of standards.
Commonly used character set standards:
ISO-8859 Western European character set, excluding full-width characters
GB2312/GBK Simplified Chinese character set
Big5 Traditional Chinese character set
UTF-8 Character set based on Unicode encoding
ANSI means using the local default character set standard
Construction method
String(byte[] bytes)
String(byte[] bytes, "Character set encoding")
String(byte[] bytes,start( Starting subscript), length (take a few))
String(char[] c)
String(char[] c,start,length)
Method:
Convert string to byte array byte bs[]=s.getBytes();//Get a string array
The string is converted into a byte array according to the specified character set byte bs[]=s.getBytes("UTF-8");
Convert the string into a character array Char c[]=s.toCharArray();
Copy some characters in the string to the character array getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin);
Get the character at the specified position char c=s.charAt(subscript);
Compare two strings in dictionary order compareTo(String anotherString);
Compare two strings in dictionary order A string, regardless of case compareToIgnoreCase(String str);
Determine whether the string contains another string contains(CharSquence(parent class) s);
Determine whether the string is based on a certain ends with a suffix endWith(String s);
Determine whether the string starts with a certain prefix startsWith(String s);
Determine whether the two strings are equal equals(String s);
Determine whether two strings are equal, ignoring case equalsInnoreCase(String s);
Determine the position of the substring in the large string indexOf(s1);
Determine the position of the substring in the large string The last occurrence position in s.lastIndexOf(s1);
Get the character length of the string .length(); The length of the array .length;
will replace the string s.replace("oldChar","newChar");
will replace the first string s.replaceFrist("oldChar","newChar");
intercept characters String s.substring(startIndex(start index));
Convert the replacement string s.substring(startIndex,endIndex(end index));
to lowercase toLowerCase(s1); Uppercase toUpperCase(s1);
Remove the blank characters at the beginning and end of the string trim();
Convert other types of data into string type String.valueOf (any type);
Cut the string String[] s=s1.split();
String class I will give an example, using two methods to display Monday to Friday
Java code
public class lianxi5 {
public static void main(String[] args) {
String z="" ; use ’ s ’ using use using ‐ ‐ ‐ ‐
char c=s.charAt (i); z = z+c;
}
for (int j = 0; j & lt; str.Length (); j ++) {
t = str.charat (j);
System.out.print(z+t+" ");
}
} System.out.println();
System.out.println(); for(int i=0;i t= str.charAt(j); System.out.print(st+t+" "); Wednesday Thursday Friday Saturday Sunday Monday Tuesday Wednesday Thursday Friday Saturday