当前位置:网站首页>Simple understanding of string
Simple understanding of string
2022-07-04 10:58:00 【Black demon fairy moon】
1.String There are two ways to create :
String s="fjy";
char[] Array={
'f','j','y'};
String s1=new String(Array);
The first method is stored in the string pool , Create only once
2. Two ways to splice strings :
Public class TestString {
public static void main(String[] args) {
String s="fjy";
char[] Array={
'f','j','y'};
String s1=new String(Array);
StringBuilder sb = new StringBuilder();
StringBuffer sb2=new StringBuffer();
for (int i = 0; i <10000; i++) {
System.out.println(sb.append(s));
//System.out.println(sb2.append(s));
}
}
}
3. Define the regular expression of the string ( Double quotation marks are required on both sides )
String regex="[0-9]{17}[0-9x]";
The regular expression to determine whether the ID number is entered correctly has not been written
Integer
new Integer(int a)
Integer.valueof(int a):
Integer.valueof(int a) This way of creating objects is quite special , When a stay -128-127 Between time , In the pool
Double
new Double(double a)
Double.valueof(double a)
There is no difference between the above two creation methods
Integet.parseInt(" “); The return value is int type
Double.parseDouble(” "); The return value is double type
Automatic packing and unpacking :
Integer.valueof(5)->Integer
Integer int1=new Integer(5);
int1.intValue()->int
BigDecimal
BigDecimal We need to pay attention to :
a:BigDecimal There are two constructors for , One is to store Double type , The other is to store String type . Generally not used Double type , Because the operation is not accurate
b:divide This method is special , There are three parameters , Respectively : Divisor , Retained decimals , rounding ( Round to the nearest , The floor , Ceiling, etc )
System.out.println(" Please enter two numbers ");
Double a=new Scanner(System.in).nextDouble();
Double b=new Scanner(System.in).nextDouble();
BigDecimal bigDecimal1 = new BigDecimal(a + "");
BigDecimal bigDecimal2 = new BigDecimal(b + "");
System.out.println(bigDecimal1.add(bigDecimal2));
System.out.println(bigDecimal1.subtract(bigDecimal2));
System.out.println(bigDecimal1.multiply(bigDecimal2));
System.out.println(bigDecimal1.divide(bigDecimal2,3, RoundingMode.HALF_UP));
边栏推荐
- Heartbeat启动后无反应
- [untitled]
- Learning XML DOM -- a typical model for parsing XML documents
- Iterator generators and modules
- /*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/
- Regular expression
- Locust learning record I
- LVS+Keepalived实现四层负载及高可用
- F12 clear the cookies of the corresponding web address
- Ten key performance indicators of software applications
猜你喜欢
Collection of practical string functions
Hidden C2 tunnel -- use of icmpsh of ICMP
Performance test method
Introduction to tree and binary tree
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
[Galaxy Kirin V10] [server] NFS setup
F12 clear the cookies of the corresponding web address
Elevator dispatching (pairing project) ②
Canoe test: two ways to create CAPL test module
Quick sort (C language)
随机推荐
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
Canoe - the third simulation project - bus simulation - 3-2 project implementation
software test
The most ideal automated testing model, how to achieve layering of automated testing
Locust installation
20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
[Galaxy Kirin V10] [server] system partition expansion
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
Canoe test: two ways to create CAPL test module
Article publishing experiment
本地Mysql忘记密码的修改方法(windows)
Canoe: the fourth simulation project -- bug debugging experience
Elevator dispatching (pairing project) ①
Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
Introduction to tree and binary tree
Common system modules and file operations
Application and Optimization Practice of redis in vivo push platform
LVS+Keepalived实现四层负载及高可用
Introduction to Lichuang EDA