当前位置:网站首页>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));
边栏推荐
- Installation of ES plug-in in Google browser
- How to deal with the relationship between colleagues
- Recursion and divide and conquer strategy
- Add t more space to your computer (no need to add hard disk)
- [untitled]
- Crawl Zhejiang industry and trade news page
- Performance test method
- Cacti主机模板之定制版
- F12 clear the cookies of the corresponding web address
- VPS安装Virtualmin面板
猜你喜欢

Huge number multiplication (C language)

How do microservices aggregate API documents? This wave of show~

Canoe test: two ways to create CAPL test module

VI text editor and user rights management, group management and time management

Fundamentals of software testing

Analysis function in SQL

Ten key performance indicators of software applications

Using Lua to realize 99 multiplication table
![[Galaxy Kirin V10] [server] soft RAID configuration](/img/d5/789387613fafc18f623d0cff45093b.jpg)
[Galaxy Kirin V10] [server] soft RAID configuration
![[Galaxy Kirin V10] [desktop] FTP common scene setup](/img/f6/e4fbfe69a6a7635ee6364114c46fd8.jpg)
[Galaxy Kirin V10] [desktop] FTP common scene setup
随机推荐
Collection of practical string functions
试题库管理系统–数据库设计[通俗易懂]
unit testing
[Galaxy Kirin V10] [server] NUMA Technology
CAPL: on sysVar_ Update difference on sysvar
Performance test overview
Analysis function in SQL
Performance test method
Elevator dispatching (pairing project) ②
Student achievement management system (C language)
Jemeter script recording
[Galaxy Kirin V10] [server] soft RAID configuration
Design and common methods of test case documents
R built in data set
[Galaxy Kirin V10] [desktop] login system flash back
Canoe - the second simulation project -xvihicle1 bus database design (operation)
Locust learning record I
JMeter correlation technology
Solaris 10网络服务
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool