当前位置:网站首页>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边栏推荐
- 排序:归并排序和快速排序
- Practice of online question feedback module (XIV): realize online question answering function
- NLP natural language processing - Introduction to machine learning and natural language processing (3)
- 「论文笔记」Next-item Recommendations in Short Sessions
- 数据库基础
- 4. Data integrity
- 依赖和关联的对比和区别
- 3.0.0 alpha blockbuster release! Nine new functions and new UI unlock new capabilities of dispatching system
- Crawler data analysis
- MMOE多目标建模
猜你喜欢

Speech at 2021 global machine learning conference

NLP natural language processing - Introduction to machine learning and natural language processing (3)

PR subtitle production

Sort: merge sort and quick sort

以太网交换安全

正则表达式规则以及常用的正则表达式

博途PLC一阶滞后系统传递函数阶跃响应输出仿真(SCL)

China Unicom transformed the Apache dolphin scheduler resource center to realize the one-stop access of cross cluster call and data script of billing environment

Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep Architectures论文翻译/笔记

Learning Efficient Convolutional Networks Through Network Slimming
随机推荐
dcn(deep cross network)三部曲
基于Thinkphp的开源管理系统
MMOE多目标建模
NFT digital collection system development: activating digital cultural heritage
[C language] do you really know printf? (printf is typically error prone, and collection is strongly recommended)
Modulenotfounderror: no module named 'pip' solution
Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep Architectures论文翻译/笔记
以太网交换安全
【uniapp】多种支付方式封装
WCF introductory tutorial II
Download and install the free version of typora
Configure flask
Devaxpress.xtraeditors.datanavigator usage
正则表达式规则以及常用的正则表达式
现在开发人员都开始做测试了,是不是以后就没有软件测试人员了?
2022.7.22DAY612
Crawler data analysis
NFT digital collection development: Six differences between digital collections and NFT
NFT digital collection development: digital art collection enabling public welfare platform
OVS underlying implementation principle