当前位置:网站首页>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边栏推荐
- hot100 哈希
- tensorflow2.x中的量化感知训练以及tflite的x86端测评
- NFT digital collection development: Six differences between digital collections and NFT
- 此章节用于补充
- 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
- NFT digital collection system development: what are the best digital marketing strategies for NFT digital collection
- NLP自然语言处理-机器学习和自然语言处理介绍(三)
- 此章节用于补充2
- Devaxpress.xtraeditors.datanavigator usage
- PR subtitle production
猜你喜欢

什么是消息订阅和发布?

Compose text and icon splicing to realize drawableleft or drawableright

NFT digital collection system development: activating digital cultural heritage

Installation of Baidu flying paste deep learning framework tutorial in Anaconda

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

OAuth2.0系列博客教程汇总

Learning Efficient Convolutional Networks Through Network Slimming

6. Backup and recovery of MySQL database

pycharm常用快捷键

现在开发人员都开始做测试了,是不是以后就没有软件测试人员了?
随机推荐
基于Thinkphp的开源管理系统
NFT数字藏品开发:数字艺术藏品赋能公益平台
ShardingSphere数据分片
NFT digital collection system development: what are the best digital marketing strategies for NFT digital collection
Compose canvas custom circular progress bar
MySQL之执行计划
Compose text and icon splicing to realize drawableleft or drawableright
【uniapp】多种支付方式封装
Download and install the free version of typora
以太网交换安全
The analysis, solution and development of the problem of router dropping frequently
Quantitative perception training in tensorflow2.x and x86 end evaluation of tflite
6、MySQL数据库的备份与恢复
Deep learning model deployment
系统架构&微服务
NFT digital collection system development: Huawei releases the first collector's digital collection
Selenium: detailed explanation of browser crawler use (I)
0动态规划 LeetCode1567. 乘积为正数的最长子数组长度
微服务feign调用时候,token丢失问题解决方案
Common templates for web development