Common classes of java system

The 8 basic types in Java all correspond to a class type

byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

Math Math function class
Math.abs(number); //Calculate the absolute value
Math.max(a , b);//Take the larger
Math.min(a, b) in ab;//Take the smaller
Math.random() in ab;//A random decimal from 0 to 1
Math.pow( a,b);//Calculate the b power of a

String: String class with fixed length
StringBuffer/StringBuilder: Variable string
String:
Construction method:
String(byte[] bs);//Construct the byte array into String
String(byte[] bs, int offset, int count);//Construct part of the byte array into a string
String(byte[] bs, "encoding name");//Construct the byte array as String

String(char[] cs);//Construct character array into string
String(char[] cs,int offset,int count);//Construct part of the characters in the character array into a string Both
byte arrays and character arrays can be turned into strings! ! ! ! In addition to calling the constructor, the creation of a string can be directly assigned String s = "abcdef"
like a basic type ; commonly used methods: charAt(int index) //Get the character at the specified subscript position compareTo(String s) / / Compare the size of two strings int t = s1.compareTo(s2); if t==0, it means that s1 and s2 are the same t<0, which means that s1 is less than s2 t>0, which means that s1 is greater than s2 contains(String s) ; Does it contain the string s endsWith(String s) Is it startsWith(String s) that ends with s Is it starts with s equals(Object s) Determine whether the string and the object s are the same getBytes() ; Change the string to Byte array, use the default encoding method getBytes(String encoding); turn the string into a byte array, using the specified encoding method toCharArray() ; turn the string into a character array s.indexOf('g'); character The first occurrence of the subscript position s.indexOf('g',4); search backward from the specified position
























s.lastIndexOf('g') Find

the number of characters in the length() string backwards

replace(old,new) Replace the specified character with a new character
replace("ab", "AB"); Replace the specified character Replace the string with a new string

split(String s); Split the string according to s

substring(int beginIndex) Extract the string
substring(int beginIndex,int endIndex) Extract the string


toLowerCase() Convert all English characters in the string Convert to lowercase
toUpperCase() Convert all English characters in the string to uppercase

trim() Remove spaces at the beginning and end of the string

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326800158&siteId=291194637