当前位置:网站首页>Common APIs
Common APIs
2022-07-03 07:06:00 【L gold p】
1.String
1、1 summary
java.lang.String: It's a string class , The bottom floor is a final Embellished char Array , therefore String Many features are the properties of arrays
For example, once the length is determined Can't change
Once the string is created , This string object cannot be changed
To improve string access and storage efficiency Java The virtual machine uses a caching mechanism , Save the strings to the string constant pool
In the process of execution , If you want to use a string a,String s1="a" First, search the character constant pool Is there a a, If not, create one If there is Sting s2="a"; No more creation , Take the existing one a return
So lead to String s1="a" String s2="a" here s1==s2 He is also true Because they point to the same string object Namely a

1、2 Basic use

1、3 Do not splice frequently


1、4 Construction method


1、5 Common methods
Study API
1 What is the function
2 What are input and output parameters
3 How to use it?
// 1 char charAt (int index ) : Returns... In the string , The character in the specified position
String s1 = "qwehihasd";
char c1 = s1.charAt(2);
// e
System.out.println(c1);
// 2 boolean endsWith(String suffix) : Determines whether the string ends with the specified string
// boolean startsWith(String prefix) : ditto , Judgment begins
System.out.println("Hello.java".endsWith(".java"));
// Note blank space , If there is a space, it won't match
System.out.println("Hello.java".endsWith(".java "));
// 3 boolean equalsIgnoreCase(String str) : Case insensitive comparison of two strings for equality
System.out.println("abc".equalsIgnoreCase("aBc"));
// 4 byte[] getBytes() : Converts a string to a byte array and returns
byte[] bytes = "abc".getBytes();
for (int i = 0; i < bytes.length; i++) {
System.out.println(bytes[i]);
}
// 5 char[] toCharArray() : Converts a string to a character array and returns
char[] chars = "abc".toCharArray();
for (int i = 0; i < chars.length; i++) {
System.out.println(chars[i]);
}
// 6 int indexOf(String str) : Gets the starting index of the specified string in the string , No return found -1
System.out.println("askdhqwbe".indexOf("kd")); // 2
System.out.println("askdhqwbe".indexOf("kda")); // -1
// 7 int indexOf(String str,int index) :
// Start at the specified location ( contain ), Gets the starting index of the specified string in the string , No return found -1
System.out.println("askdhaqwbe".indexOf("a", 5)); // -1
// 8 index lastIndexOf(String str) : ditto , The last index to appear No return found -1
System.out.println("askdhaqwbe".lastIndexOf("a")); // 5
// 9 int length() : Returns the length of the string
System.out.println("abc".length());
// 10 String replaceAll(String regex . String replacement);
// Replace specified characters , regular expression
// String replace (String str . String replacement); Regular expressions are not supported
// use 1 hold a Replaced and returned a new string
// regular expression , But I didn't write regular expressions There is no difference
System.out.println("hucgasdqweasd".replaceAll("a", "1"));
System.out.println("hucgasdqweasd".replace("a", "1"));
// because . In regular expressions , Arbitrary character
System.out.println("qwe.rty.yui.uio".replaceAll(".", ","));
// have access to \ escape
System.out.println("qwe.rty.yui.uio".replaceAll("\\.", ","));
System.out.println("qwe.rty.yui.uio".replace(".", ","));
// 11 String[] split(String regex) : Split string , Return string array , regular expression , Be careful .....
// spot , Need to escape
String s2 = "2022.1.14";
String[] arr = s2.split("\\.");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
// 12 String substring(int begin); In the string , Substring starting with a subscript ( contain )
System.out.println("abcdef".substring(2));// cdef
// 13 String substring(int begin, int end) :
// In the string , Start with a subscript ( contain ) Substring ending at a subscript ( It doesn't contain )
System.out.println("abcdef".substring(2, 4));// cd
// 14 String trim() : Remove the spaces on both sides of the string
System.out
.println(" a d sadasd ");
System.out
.println(" a d sadasd "
.trim());
// 15 String toUpperCase() : Turn capitalization
// String toLowerCase() : Turn lowercase
System.out.println("asd".toUpperCase());
// 16 static String valueOf(Object obj) :
// Calling the toString Method , If null, No more calls toString Instead, it returns a string null
String_05 s = null;
// When printing a reference type , Automatically called String Of valueOf therefore Automatically called toString Method
System.out.println(s);
1、6 Be careful




2、StringBuffer and StringBuilder
2、1 summary

2、2 Basic use

2、3 Common methods

3、 Packaging
3、1 summary
【 ask 】 Want to do more with basic type data , What do I do ?
【 answer 】 The most convenient way is to encapsulate it as an object . Because more properties and behaviors can be defined in the object description to operate on the basic data type . We don't need to encapsulate basic types by ourselves ,JDK It has been encapsulated for us .
【 Concept 】
1. Boxing is the automatic conversion of basic data types to wrapper types
2. Unpacking is automatically converting the wrapper type to the basic data type

3、2 Use

3.3 Integer
3.3.1 Basic use

3.3.2 transformation

3.3.3 Common methods

3.3.4 Automatic packing and unpacking


3.3.5、 Deep shaping constant pool

Judge the current value Whether in -128~127 Between
If it's not in range Just directly new object




3.3.6 summary


4.System
4.1 summary
System Class provides the public static long currentTimeMillis() Used to return the current time Between and 1970 year 1 month 1 Japan 0 when 0 branch 0 The time difference in milliseconds between seconds .
This method is suitable for calculating time difference .
System Class represents system , Many system level properties and control methods are placed inside the class . This class is located in java.lang package .
Because the constructor of this class is private Of , So we can't create objects of this class , That is, it can't be realized Instantiate this class . Its internal member variables and member methods are static Of , So it can also be very convenient To call .
Member variables
System Class contains in、out and err Three member variables , They represent the standard input stream
( Keyboard entry ), Standard output stream ( Monitor ) And standard error output stream ( Monitor ).
Member method
native long currentTimeMillis():
The function of this method is to return the current computer time , Time is expressed in the current computer
Between and GMT Time ( Greenwich mean time )1970 year 1 month 1 Number 0 when 0 branch 0 The number of milliseconds in seconds .
void exit(int status):
The function of this method is to exit the program . among status The value of is 0 It means normal exit , Non zero means
Abnormal exit . Using this method, the exit function of program can be realized in GUI programming .
4.2 Common methods

5.Date
5.1 summary
Get time and time operations
5.2 Construction method

5.3 Common methods

5.4 format

5.5 Calendar

6. Random
6.1 summary Random number from 0 Start
6.2 Use
边栏推荐
- LeetCode
- MySQL mistakenly deleted the root account and failed to log in
- Split small interface
- Dbnet: real time scene text detection with differentiable binarization
- Mise en place d'un environnement de développement de fonctions personnalisées
- 2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
- 20220319
- 保险公司怎么查高血压?
- Resttemplate configuration use
- Personally design a highly concurrent seckill system
猜你喜欢

10000小時定律不會讓你成為編程大師,但至少是個好的起點
![Gridome + strapi + vercel + PM2 deployment case of [static site (3)]](/img/65/8d79998e96a2c74ba6e237bee652c6.jpg)
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
![[set theory] partition (partition | partition example | partition and equivalence relationship)](/img/f0/c3c82de52d563f3b81d731ba74e3a2.jpg)
[set theory] partition (partition | partition example | partition and equivalence relationship)

Asynchronous programming: async/await in asp Net

My 2020 summary "don't love the past, indulge in moving forward"

2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)

Basic components and intermediate components

熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?

golang操作redis:写入、读取hash类型数据

2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
随机推荐
Personally design a highly concurrent seckill system
instanceof
How can the server set up multiple interfaces and install IIS? Tiantian gives you the answer!
The pressure of large institutions in the bear market has doubled. Will the giant whales such as gray scale, tether and micro strategy become 'giant thunder'?
Resthighlevelclient gets the mapping of an index
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
Use the jvisualvm tool ----- tocmat to start JMX monitoring
Sorting out the core ideas of the pyramid principle
JMeter JSON extractor extracts two parameters at the same time
Basic components and intermediate components
php artisan
Golang operation redis: write and read kV data
Software testing assignment - the next day
JUC forkjoinpool branch merge framework - work theft
4279. Cartesian tree
Daily question brushing record (11)
10000小时定律不会让你成为编程大师,但至少是个好的起点
[day15] introduce the features, advantages and disadvantages of promise, and how to implement it internally. Implement promise by hand
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
CentOS php7.3 installing redis extensions
