当前位置:网站首页>2022-07-28 study notes of group 4 self-cultivation class (every day)
2022-07-28 study notes of group 4 self-cultivation class (every day)
2022-07-29 03:13:00 【Self cultivation class】
API, Application programming interface .java API It's a programmer's Dictionary , yes JDK The description document of the class provided to us in , We can check API The way , To learn java Class provided , And learn how to use them .
API Use steps :
Open help document .
Click to display , Find the index , See the input box .
Who are you looking for ? Enter... In the input box , And then go back .
Look at the bag .java.lang The following classes don't need a guide package , Other needs .
Look at the explanation and description of the class .
Learn how to construct .
Use the member method .
Scanner class
Scanner Use steps
1、 view classes
java.util.Scanner: This class needs import Use... After import
2、 Look at the construction method
public Scanner: Construct a new Scanner, The value it generates is scanned from the specified input stream .
3、 View member methods
public int nextInt(): Scan the next tag of the input information as a int value , Use Scanner class , Complete the operation of receiving keyboard input data

Random
Examples of this class are used to generate pseudo-random numbers

Random Use steps
view classes :
java.util.Random: This class needs to be used after bootstrapping .
Look at the construction method public Random(): Create a random array
View member methods public int nextInt(int n): Returns a pseudo-random number , The scope is 0( Include ) and Specify the value n( barring ) Between int value
Create a Random object , Every time you call nextInt() Method , Will generate a random number
Arraylist class
java.util.ArrayList Is the implementation of variable size array , Data stored inside is called an element , This class provides some methods to manipulate internal storage elements .ArrayList Elements can be added continuously , It also grows in size
ArrayList The bottom layer of the collection adopts the data structure of array
ArrayList Collection is not thread safe
ArrayList Set initialization capacity 10
ArrayList The bottom of the set is Object An array of types Object[]
1、ArrayList Class is located java.util In bag , You need to quote it before using , The syntax is as follows :
import java.util.ArrayList;// quote ArrayList class
ArrayList<E> objectName=new ArrayList<>();// initialization
E: Generic data types , Used for setting up objectName Data type of , Only data types can be referenced
2、ArrayList It's an array queue , Provides related additions 、 Delete 、 modify 、 Ergodic function
2.1、 Add elements to ArrayList have access to add() Method

2.2、 visit ArrayList Elements in can be used get() Method :

2.3、 modify ArrayList Elements in can be used set() Method :

2.4、 Delete ArrayList Elements in can be used remove() Method

2.5、 Calculation ArrayList The number of elements in can be used size() Method

2.6、 use for Loop through the elements in the array list

2.7for-each To traverse

3、 Other reference data types
4、ArrayList Sort
Collections class It is also a very useful class , be located java.util In bag , Provided sort() Method to sort a list of characters or numbers

String class
java.lang.String Class represents string . This class does not need to be imported
1、String Class creation object
use String Class creation objects usually have two forms :
1.1、String str="cxy";
2.2、String str =new String("cxy");
2、String Common methods of class
1.1、 Get string length :
Variable name .length();

2.1、 Get the position of the character in the string
Variable name .indexOf (String str);
Search from the beginning str First occurrence in string ;
Variable name .indexOf(String str,int fromIndex);
From the subscript fromIndex Start searching at str First occurrence in string
Variable name .lastIndexOf(String str);
Start at the tail and find str Last occurrence in string
Variable name .lastIndexOf(String str,int fromIndex);
From the subscript fromIndex Start searching at str Last occurrence in string

2.2、 Get the character at a certain position of the string
Variable name .charAt(int index);
The index of the search string is Index String of positions

2.3、 Intercepting string
Variable name .substring(fromindex,endlndex);
from fromIndex Start intercepting at endIndex At the end of , Does not contain the subscript endIndex The characters of ;
Variable name .substring(fromIndex);
from fromIndex From the beginning to the end ;

2.4、 Split the string into an array
Variable name 1.split(String str2);

static keyword
1、 Class variables :
When static When decorating member variables , This variable is called a class variable
give an example : static int num;
2、 Static methods
When static When decorating member methods , This method is called class method
Definition :
Modifier static return type Method name ( parameter list ){
}
3、 Considerations for static method calls
3.1、 Static methods can directly access class variables and static methods
3.2、 Static methods cannot directly access ordinary member variables or member methods . Member methods can directly access class variables and static methods
3.3、 In the static method , Out of commission this keyword
Static methods can only access static members
4、 Static code block
4.1、 Location : Class
4.2、 perform : It is executed as the class is loaded and once , Prior to the main Execution of methods and construction methods
Format :
public class Name{
static{
Execute statement
}
}effect : Initialize and assign values to class variables
Arrays class
java.util.Arrays This class contains various methods of manipulating arrays
1、 How to operate the array
public static String toString(int[] a) : Returns a string representation of the contents of a specified array
public static void sort(int[] a) : For the specified int Type arrays are sorted in numerical ascending order

Math class
java.lang.Math Class contains methods for performing basic mathematical operations , Such as the primary index 、 logarithm 、 Square root and trigonometric function
1、public static double abs(double a) : return double The absolute value of value
2、public static double ceil(double a) : Returns the smallest integer greater than or equal to the parameter
3、public static double floor(double a) : Returns an integer less than or equal to the maximum parameter
4、public static long round(double a) : Returns the closest parameter long( It's equivalent to rounding )
Object class
java.lang.Object Class is Java The root class in language , When an object is instantiated , The ultimate parent is Object
If a class has no specially specified parent , Then the default is to inherit Object class
public String toString(): Returns the string representation of the object
toString Method returns the memory address , In development , It is often necessary to get the corresponding string representation according to the properties of the object , So we have to rewrite
Rewriting covers
public boolean equals(Object obj): Indicates whether some other object is associated with this object “ equal ”
To compare two strings, you must use equals Method , Out of commission "=="
Date time class
1、Date class
java.util.Date class Represents a specific moment , Accurate to milliseconds
Common methods
边栏推荐
- 服务器运行管理制度
- 2022-07-28 第四小组 修身课 学习笔记(every day)
- Introduction and advanced MySQL (13)
- 带你来浅聊一下,单商户功能模块汇总
- 2. Nodejs -- path (\dirname, \filname), URL URL, querystring module, mime module, various paths (relative paths), web page loading (interview questions *)
- 年内首个“三连跌” 95号汽油回归“8元时代“
- Linux下安装MySQL8.0的详细步骤
- 「PHP基础知识」输出圆周率的近似值
- 力扣刷题之数组序号计算(每日一题7/28)
- VIM common commands
猜你喜欢

vasp计算任务报错:M_divide:can not subdivide 8 nodes by 6

Verilog: blocking assignment and non blocking assignment

HTB-Blocky

第09章_性能分析工具的使用

Calculation of array serial number of force deduction questions (daily question 7/28)

爆肝整理JVM十大模块知识点总结,不信你还不懂

C语言基础知识点汇总

12_ue4进阶_换一个更好看的人物模型

What is eplato cast by Plato farm on elephant swap? Why is there a high premium?

2022-07-28 顾宇佳 学习笔记
随机推荐
What is SOA (Service Oriented Architecture)?
Production deployment zabbix5.0 notes
Object转String的几种方法
Chapter 2 VRP command line
MySQL large table joint query optimization, large transaction optimization, avoiding transaction timeout, lock wait timeout and lock table
The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled
2. Nodejs -- path (\dirname, \filname), URL URL, querystring module, mime module, various paths (relative paths), web page loading (interview questions *)
反脆弱·从不确定性中获益---管理?
Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.
Feedback function of conference OA
How dare you write a resume that is proficient in concurrent programming? Why do you use a two-way linked list in AQS?
算法---粉刷房子(Kotlin)
C陷阱与缺陷 第3章 语义“陷阱” 3.1 指针与数组
C陷阱与缺陷 第3章 语义“陷阱” 3.9 整数溢出
Engineering boy: under 20 years old, ordinary but not mediocre
融云 IM & RTC 能力上新盘点
SAP 中国本地化内容汇总
C traps and defects Chapter 3 semantic "traps" 3.3 array declaration as parameters
Verilog的时间系统任务----$time、$stime、$realtime
[robot learning] matlab kinematics and ADMAS dynamics analysis of manipulator gripper