当前位置:网站首页>Erudite Valley Learning Records] Super summary, attentive sharing | common APIs
Erudite Valley Learning Records] Super summary, attentive sharing | common APIs
2022-07-28 07:04:00 【Jilei mountain Moyun cave】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
【 Erudite Valley IT Technical support 】
Commonly used API
Math Common methods of class
Method name explain
public static int abs(int a) Returns the absolute value of the parameter
public static double ceil(double a) Rounding up
public static double floor(double a) Rounding down
public static int round(float a) rounding
public static int max(int a,int b) Return to two int The larger of the values
public static int min(int a,int b) Return to two int The smaller of the values
public static double pow(double a,double b) return a Of b The value of the power
public static double random() The return value is double Positive value of ,[0.0,1.0)
System Class Overview
System Can't be instantiated
public static void exit(int status) Terminate the currently running Java virtual machine ,0 It means normal exit , Non zero means abnormal exit
public static long currentTimeMillis() Return current time ( In Milliseconds )
arraycopy( Data source array , Starting index , Destination array , Starting index , Number of copies ) Array copy
// arraycopy( Data source array , Starting index , Destination array , Starting index , Number of copies )
int[] arr1 = {
1, 2, 3, 4, 5};
int[] arr2 = new int[10];
System.arraycopy(arr1, 0,arr2,0,arr1.length);
for (int i = 0; i < arr2.length; i++) {
System.out.print(arr2[i]); // 1234500000
}
Object Class overview
Each class can put Object As parent . All classes inherit directly or indirectly from this class
Construction method :public Object()
- Object Class is the direct or indirect parent of all classes
- To print an object directly is to print the object toString Return value of method
- Object Class toString Method gets the address value of the object
- We are usually right about toString Method
- public String toString() Returns the string representation of the object . It is recommended that all subclasses override this method , Automatic generation
- public boolean equals( Another object ) Compare objects for equality . Default comparison address , Rewriting can compare content , Automatic generation
Objects Common methods of class
- public static String toString( object ) Returns the string representation of the object in the parameter .
- public static String toString( object , Default string ) Returns the string representation of the object .
- public static Boolean isNull( object ) Determines if the object is null
- public static Boolean nonNull( object ) Judge whether the object is not empty
BigDecimal Common methods of class
effect : Can be used to accurately calculate
public BigDecimal add( the other one BigDecimal object ) Add
public BigDecimal subtract ( the other one BigDecimal object ) Subtraction
public BigDecimal multiply ( the other one BigDecimal object ) Multiplication
public BigDecimal divide ( the other one BigDecimal object ) division
public BigDecimal divide ( the other one BigDecimal object , How many exactly , rounding mode ) division
BigDecimal divide = bd1.divide( The objects involved in the operation , How many places after the decimal point , rounding mode );
BigDecimal bd1 = new BigDecimal("7.7");
BigDecimal bd2 = new BigDecimal("3");
BigDecimal divide = bd1.divide(bd2, 2, BigDecimal.ROUND_UP);// Jin Yi
BigDecimal divide2 = bd1.divide(bd2, 2, BigDecimal.ROUND_FLOOR);// Decapitation
BigDecimal divide3 = bd1.divide(bd2, 2, BigDecimal.ROUND_HALF_UP);// rounding
System.out.println(divide3);//2.57
System.out.println(divide2);//2.56
System.out.println(divide);// 2.57
Basic type packaging
Automatic boxing : Put a basic data type The wrapper class corresponding to the variable ,java The bottom layer will help us automatically call valueOf Method
Automatic dismantling : Put a packaging type Become the corresponding basic data type
Integer: A basic data type is wrapped in this object int Value
Method name explain
public Integer(int value) according to int Value creation Integer object ( obsolete )
public Integer(String s) according to String Value creation Integer object ( obsolete )
public static Integer valueOf(int i) Returns the specified int It's worth it Integer example
public static Integer valueOf(String s) Returns a... That holds the specified value Integer object String
Integer i3 = Integer.valueOf(200); // Returns the specified int It's worth it Integer example
Integer i4 = Integer.valueOf("200"); // Returns a... That holds the specified value Integer object String
System.out.println(i3); // 200
System.out.println(i4); // 200
Be careful : When using wrapper class types , If operation , It's best to judge whether it is null
What we recommend is , As long as it's an object , Before use, it must be carried out not for null The judgment of the
- int Convert to String
Mode one : Just add double quotation marks
Mode two :public static String valueOf(int i): return int String representation of parameter . The method is String Methods in class - String Convert to int
public static int parseInt(String s): Parse string to int type . The method is Integer Methods in class
String s1 = "100";
int i2 = Integer.parseInt(s1);
System.out.println(i2+i1); // 300
Arrays Class overview and common methods
- public static String toString(int[] a) Returns a string representation of the contents of the specified array
- public static void sort(int[] a) Arranges the specified array in numerical order
- public static int binarySearch(int[] a, int key) Use binary search to return the index of the specified element
int[] arr = {
3,2,4,6,7};
System.out.println(Arrays.toString(arr)); // [3, 2, 4, 6, 7]
Arrays.sort(arr);
System.out.println(Arrays.toString(arr)); // [2, 3, 4, 6, 7]
int index = Arrays.binarySearch(arr, 7);
System.out.println(index); //4
边栏推荐
- MOOC翁恺C语言 第四周:进一步的判断与循环:3.多路分支4.循环的例子5.判断和循环常见的错误
- Qgraphicsview promoted to qchartview
- About gcc:multiple definition of
- MOOC Weng Kai C language week 5: 1. cycle control 2. multiple cycles 3. cycle application
- MOOC Weng Kai C language fourth week: further judgment and circulation: 1. Logical types and operations 2. Judgment of cascading and nesting
- SSH服务配置
- DOM operation cases
- Test interview questions collection (III) | computer network and database (with answers)
- JS string method Encyclopedia
- Tcp/ip five layer model
猜你喜欢

Installation and configuration of unit test framework jest with typescript

MOOC翁恺C语言 第四周:进一步的判断与循环:3.多路分支4.循环的例子5.判断和循环常见的错误

SSH service configuration

Shell script - sort, uniq, TR, array sort, cut, Eval command configuration

三层交换和VRRP

PXE无人值守安装管理

Canvas drawing 1

Build php7 private warehouse

Blue Bridge Cup square filling number

bond模式配置
随机推荐
Wechat applet custom compilation mode
MOOC翁恺 C语言 第三周:判断与循环:1.判断
PXE无人值守安装管理
DOM -- page rendering, style attribute operation, preloading and lazy loading, anti shake and throttling
[learning notes] VIM editor
bond模式配置
Custom component -- communication between parent and child components
Hdu-5783 divide the sequence (greedy water question)
Technology sharing | how to do Assertion Verification in interface automated testing?
Monotonic queue, Luogu p1886 sliding window
shell脚本——正则表达式
Results fill in the blank shopping list (teach you to solve it with Excel)
DNS domain name resolution
Technology sharing | sending requests using curl
Pku-2739-sum of constructive prime numbers
YUM仓库的搭建
Esxi community network card driver updated in March 2022
DOM Foundation
NFS shared storage service
Animation animation realizes the crossing (click) pause