当前位置:网站首页>Summary of common methods of string
Summary of common methods of string
2022-07-26 07:50:00 【I like iced black tea】
List of articles
One 、 Construction method
There are two kinds of construction methods in the string, namely, non parametric construction method and parametric construction method
1、String s1=" China ";
2、String s2=new String(“ China ”);// Create an object , Point to string constant object .
3、String s3=new String(char Array );// take char Each character stored in the array is connected to form a string
4、String s3=new String(char Array , Start subscript , length );// take char From the starting position of the storage in the array lenth Characters form a string
5、String s3=new String(byte Array );// take byte The numbers stored in the array are spliced into a string
6、String s3=new String(byte Array , Start subscript , length );// take byte The number stored in the array is from the starting subscript to the starting subscript + length , Concatenate into strings .
Two 、 Static methods
Common static methods
public static String copyValueOf(char[] data)
Returns the string representing the character sequence in the specified array
public static String copyValueOf(char[] data, int offset, int count)
Returns the string representing the character sequence in the specified array
3.public static Stirng format(String format, Object... args)
Format output string
4.public static Stirng format(Locale locale, String format, Object... args)
Use the specified language environment , Format output string
5.public static String join(CharSequence delimiter, CharSequence... elements)
Pass in parameters to replace placeholders , Generate a new string
3、 ... and 、 Other methods
1. public int indexOf(String str) Find the position of the incoming string in the current string backwards from the starting position , There is a return subscript , There is no return -1
2.public int lastIndexOf(String str) Find the position of the incoming string in the current string from the end position forward , There is a return subscript , There is no return -1
3. public boolean contains(CharSequence s) Finding the passed in parameter backwards from the start position can make the character type or string type , Return to one boolean Type value , Found return true, Otherwise return to false
4.public String substring(int beginIndex, int endIndex) from beginIndex Start to endIndex end , Intercept the current string , And return a new string
5.public String trim() Remove strings " Both ends " Space wrap ( Blank character , And return a new string
6. public String replace(char oldChar, char newChar) String replaces the old string , And return a new string
7.public String[] split(String regex) As specified regex( Regular expressions ) Split the string , Returns a new string array
8.public byte[] getBytes() Get the encoded value of the string , The default is Unicode code
边栏推荐
- How to ensure the double write consistency between cache and database?
- 给项目日志加上traceid
- Anaconda 中安装 百度飞浆Paddle 深度学习框架 教程
- C language keyword extern
- Crawler - > tpimgspider
- 时间序列分析预测实战之ARIMA模型
- Fang Wenshan, Jay Chou's best partner, will officially announce "Hualiu yuancosmos" on July 25
- [daily question 1] 919. Complete binary tree inserter
- 在线问题反馈模块实战(十四):实现在线答疑功能
- The analysis, solution and development of the problem of router dropping frequently
猜你喜欢

Sort: merge sort and quick sort

【每日一题】919. 完全二叉树插入器

Parameterization of JMeter performance test using CSV file

dcn(deep cross network)三部曲

Fang Wenshan, Jay Chou's best partner, will officially announce "Hualiu yuancosmos" on July 25

Regression analysis code implementation

记一次路由器频繁掉线问题的分析、解决与发展

ARIMA model for time series analysis and prediction

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

Summarize the common high-frequency interview questions of the software testing post
随机推荐
Yaml language-01 (data type, array, object)
动态性能视图概述
Learning Efficient Convolutional Networks Through Network Slimming
博途PLC一阶滞后系统传递函数阶跃响应输出仿真(SCL)
PHP environment deployment
【推荐系统经典论文(十)】阿里SDM模型
Leetcode 206. reverse chain list (2022.07.25)
Comparison and difference between dependence and Association
2022.7.22DAY612
Sort: merge sort and quick sort
在线问题反馈模块实战(十四):实现在线答疑功能
Regression analysis code implementation
KDD2022 | 揭秘快手短视频推荐Re-ranking之谜,相关推荐新SOTA
2021全球机器学习大会演讲稿
The bigger the project is, the bigger it is. This is how I split it
table 固定特定行
IDEA settings设置快捷键实现字符串中的英文字母转大小写
Use of views
2019中兴捧月·模型压缩方案
Hcip--- BGP comprehensive experiment