当前位置:网站首页>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 顾宇佳 学习笔记
- 军品研制过程-转阶段
- 扫雷简单版
- centos安装mysql8
- 融云 IM & RTC 能力上新盘点
- 生产部署zabbix5.0笔记
- Li Shuo, vice president of Baidu: it's a good thing that China's labor costs rise with the support of digital technology
- MySQL忘记密码怎么办
- MySQL operation database data error: fatal error encoded during command execution
- Typescript learning (I)
猜你喜欢

How dare you write a resume that is proficient in concurrent programming? Why do you use a two-way linked list in AQS?

Chapter 09_ Use of performance analysis tools

Unity 之游戏特效

Watermelon book learning Chapter 6 -- SVM

Wechat's crazy use of glide - life cycle learning

Shell编程规范与变量

【FreeSwitch开发实践】media bug获取通话语音流

IDEA安装后无法启动

Navicat new database

Verilog:阻塞赋值和非阻塞赋值
随机推荐
What if MySQL forgets the password
C language small project - address book (static version + dynamic version + file version)
MYSQL入门与进阶(十一)
Verilog: blocking assignment and non blocking assignment
Shell programming specifications and variables
第09章_性能分析工具的使用
The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled
《QA离业务代码能有多近?》通过codediff直接暴露缺陷
C traps and defects Chapter 3 semantic "traps" 3.4 avoid "couple method"
Score addition and subtraction of force deduction and brushing questions (one question per day 7/27)
What is SOA (Service Oriented Architecture)?
照片比例校正工具:DxO ViewPoint 3 直装版
C traps and defects Chapter 2 syntax "traps" 2.6 problems caused by "hanging" else
MySql的安装配置超详细教程与简单的建库建表方法
C陷阱与缺陷 第3章 语义“陷阱” 3.8 运算符&&、||和!
Engineering boy: under 20 years old, ordinary but not mediocre
During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“
基于单片机烟雾温湿度甲醛监测设计
C traps and defects Chapter 3 semantic "traps" 3.7 evaluation order
"PHP Basics" output approximate value of PI