当前位置:网站首页>API (common class 2)
API (common class 2)
2022-07-26 07:32:00 【Mourning】
1.String class
- byte[] getBytes()
- char[] toCharArray()
- static String valueOf(char[] chs)
- String toLowerCase()
- String toUpperCase()
- String concat(String str)
- Stirng[] split( Separator );
- String replace(char old,char new)
- String replace(String old,String new)
- replaceAll(String regex, String replacement)
- replaceFirst(String regex, String replacement)
- String trim()
String a=" China ";
byte[] b=a.getBytes("utf-8");// Convert the string to Byte Array
String c=new String();// take Byte Array to string
System.out.println(Arrays.toString(b));// The array needs Arrays.toString Output
System.out.println(c);// Non array direct output
String a1=" China ";
char[] c1=a1.toCharArray();// Output the string directly as an array
System.out.println(Arrays.toString(c1));int i=Integer.parseInt("10");// Convert string to basic type
Integer ii=new Integer("20");// Convert string to wrapper type
String c= "null";
String s=String.valueOf(c);
//public static String valueOf(Object obj) {
// return (obj == null) ? "null" : obj.toString();
// It is recommended to convert other types to String when , Use valueOf()
System.out.println(i);//10
System.out.println(ii);//20
System.out.println(s);//null
String a=" abC1deab23fG ";
System.out.println(a.toLowerCase(Locale.forLanguageTag(a)));// Convert all characters to lowercase
System.out.println(a.toUpperCase(Locale.forLanguageTag(a)));// Capitalize all characters
String b="abc";
String d=b.concat("efg");// Connection string
System.out.println(d);
String a1="a,b,c,d";
String[]a2=a1.split(",");// Split returns array values
System.out.println(Arrays.toString(a2));
String a3=a.replace("ab","AA");// Replace
System.out.println(a3);
String a4=a.replaceAll("ab","BB");// Replace , Regular expressions
System.out.println(a4);
String a5=a.replaceAll("\\d","");
System.out.println(a5);
int a6=a.trim().length();// Remove the space at both ends
System.out.println(a.length());
System.out.println(a6);2.StringBuffer class
summary : If we splice strings , Every splicing , Will build a new String object , Time consuming , It's a waste of space . and StringBuffer And then we can solve this problem Thread safe variable character sequence .
String、StringBuilder and Stringbuffer The difference between :
- StringBuffer It is a multi-threaded operation and the safe methods are synchronized Keyword modification .
- StringBuilder A single thread , High security .
- String Immutable value , A few splicing operations can , A large number of operations are not recommended .
The same thing : The underlying implementation is completely consistent , Inside the class, there is a char Array , No, final modification , After that, the increase and decrease of object characters are direct operations on the underlying array .
Reverse function :
public StringBuffer reverse()
Interception function :
public String substring(int start)
public String substring(int start,int end)
Add functionality :
public StringBuffer append(String str)
public StringBuffer insert(int offset,String str)
Delete function :
public StringBuffer deleteCharAt(int index)
public StringBuffer delete(int start,int end)
Replacement function :
public StringBuffer replace(int start,int end,String str)
// StringBuffer(): Variable string with buffer , If you need a lot of character splicing , It is recommended to use ~;
StringBuffer s=new StringBuffer("abcdefg");
s.append("AA");// Add... To the end by default
s.append("BB");
s.append("CC");
s.append("DD");
s.append("FF");
s.insert(0,"P");// Insert... At specified location
s.delete(0,4);// Delete the specified interval
s.deleteCharAt(3);// Delete... In the specified location
s.replace(0,2,"zp");// Specify interval substitution
s.reverse();// Reverse string
String s2=s.substring(0,5);// Intercept an interval and reassign it to a new object
StringBuilder s1=new StringBuilder("drtg");// The underlying method is similar to StringBuffer equally
System.out.println(s);
System.out.println(s2);3.Math class :
- abs The absolute value
- sqrt square root
- pow(double a, double b) a Of b The next power
- max(double a, double b)
- min(double a, double b)
- random() return 0.0 To 1.0 The random number
- long round(double a) double Data of type a Convert to long type ( rounding )
System.out.println(Math.floor(9.1));
System.out.println(Math.ceil(9.5));
System.out.println(Math.round(4.4));
System.out.println(Math.round(9.5));
System.out.println(Math.random());
Random random= new Random();
System.out.println(random.nextBoolean());
System.out.println(random.nextLong());
System.out.println(random.nextInt());
byte []bytes=new byte[5];
random.nextBytes(bytes);// no return value
System.out.println(Arrays.toString(bytes));3.Random class :
- random.nextLong() Return random number
- random.nextBoolean() Random return true and false
- random.nextint() from 0( contain ) To the specified number ( It doesn't contain )
- random.nextBytes()
4.Date class :
Date date=new Date();// Create a date object , This object contains program meteorites The time of that moment
System.out.println(date.getTime());// since 1970 1-1 0:0:0~ Milliseconds up to now
// Method with strikethrough , Deemed expired method ,api There is a new way to replace , have access to
System.out.println(date.getDate());
System.out.println(date.getClass());
System.out.println(date.getDay());
System.out.println(date.getHours());
System.out.println(date.getMinutes());
System.out.println(date.getMonth());
System.out. println(date.getSeconds());
System.out.println(date.getYear());
System.out.println(date.getTimezoneOffset());
System.out.println(date);5.Calendar
Generalization :Calendar Class is an abstract class , The object that implements a specific subclass in actual use , establish The process of object is transparent to programmers , Just use getInstance Method creation that will do .
// Contains richer calendar information
Calendar calender=new GregorianCalendar();
Calendar calendar1=new GregorianCalendar();
System.out.println(calendar1.getTime());
System.out.println(calendar1.get(Calendar.YEAR));
System.out.println(calendar1.get(Calendar.PM));6.SimpleDateFormat class
SimpleDateFormat Date formatting class
● Construction method
SimpleDateFormat( Format ); // yyyy-MM-dd
● Date to string
Date now=new Date();
myFmt.format(now);
● String to date
myFmt.parse(“2018-02-10”);
String date format and The specified format must be consistent
for example :String s = “2018-03-15”;
new SimpleDateFormat(“yyyy-MM-dd”);
Date date=new Date();
SimpleDateFormat a=new SimpleDateFormat("yyyy-MM-dd ");
String c=a.format(date);//date Type to string type
System.out.println(c);
String b="2020-1-1";
SimpleDateFormat d=new SimpleDateFormat("yyyy-MM-dd");
System.out.println(b);
try{
Date date1=d.parse(b);// String to date type
System.out.println(date1);
}
catch(ParseException e){
e.printStackTrace();
}
7.BigInteger class
stay Java in , There are many digital processing classes , such as Integer class , however Integer Class has certain limitations .
● We all know Integer yes Int The wrapper class ,int The maximum value of is 2^31-1. If you wish to describe Larger integer data , Use Integer Data types cannot be implemented , therefore Java Provided in BigInteger class .
● BigInteger The number range of type is Integer,Long The number range of types is much larger , Other branches An integer of arbitrary precision , In other words, in the operation BigInteger Type can accurately represent any The integer value of the size without losing any information .
8.BigDecimal class
System.out.println(11-10.9);// The result is 0.0999999999964
BigDecimal bigDecimal=new BigDecimal("11");
BigDecimal bigDecimal1=new BigDecimal("10.9");
System.out.println(bigDecimal.subtract(bigDecimal1));// The result is 0.1边栏推荐
- 5、多表查询
- 5. Multi table query
- How to ensure the double write consistency between cache and database?
- OVSDB
- LeetCode剑指offer专项(一)整数
- 【每日一题】919. 完全二叉树插入器
- Tensorflow learning diary tflearn
- 以太网交换安全
- The interface automation test with a monthly salary of 12k+ takes you to get started in 3 minutes
- What is message subscription and publishing?
猜你喜欢

What is bloom filter in redis series?

WCF deployed on IIS

Regular expression rules and common regular expressions
![[classic thesis of recommendation system (10)] Alibaba SDM model](/img/a5/3ae37b847042ffb34e436720f61d17.png)
[classic thesis of recommendation system (10)] Alibaba SDM model

Deep learning model deployment

NFT digital collection system development: Huawei releases the first collector's digital collection

PXE efficient batch network installation

PR subtitle production

时间序列分析预测实战之ARIMA模型
![PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts](/img/ba/28afaead68c9ff47d15d5c5395d9ce.png)
PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts
随机推荐
Regular expression rules and common regular expressions
WCF 入门教程二
依赖和关联的对比和区别
This section is for Supplement 2
博途PLC一阶滞后系统传递函数阶跃响应输出仿真(SCL)
Examples of financial tasks: real-time and offline approval of three scenarios and five optimizations of Apache dolphin scheduler in Xinwang bank
IDEA快捷键
Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep Architectures论文翻译/笔记
MMOE多目标建模
2022.7.22DAY612
HOT100 hash
PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts
微服务feign调用时候,token丢失问题解决方案
JMeter性能测试之使用CSV文件参数化
OVS underlying implementation principle
PXE efficient batch network installation
Leetcode 206. reverse chain list (2022.07.25)
Learning Efficient Convolutional Networks Through Network Slimming
Compose canvas custom circular progress bar
WCF introductory tutorial II