当前位置:网站首页>String common API
String common API
2022-06-30 15:40:00 【Frog claw white】
String Commonly used API
1、public int length() Returns the length of this string
2、public char charAt(int index) Get the character at an index position
3、public char[] toCharArray(): Converts the current string into a character array and returns
4、public String substring(int beginIndex, int endIndex) Intercept according to the start and end indexes , Get the new string ( Not before, not after )
5、public String substring(int beginIndex) Intercept from the incoming index , Intercept to the end , Get the new string
6、public String replace(CharSequence target,
7、CharSequence replacement) Use new value , Replace the old value in the string with , Get the new string
9、public String[] split(String regex) Cut the string according to the incoming rules , Get string array return
/* * String Commonly used API * */
public class StringDemo4 {
public static void main(String[] args) {
//public int length() Returns the length of this string
String name = " I love you China love";
System.out.println(name.length());
//public char charAt(int index) Get the character at an index position
char c = name.charAt(1);
System.out.println(c);
System.out.println("----------- Each character in the convenience string -----------");
for (int i = 0; i < name.length(); i++) {
char ch = name.charAt(i);
System.out.println(ch);
}
//public char[] toCharArray(): Converts the current string into a character array and returns
System.out.println("----------- String into character array -----------");
char[] chars = name.toCharArray();
for (int i = 0; i < chars.length; i++) {
char ch = chars[i];
System.out.println(ch);
}
//public String substring(int beginIndex, int endIndex) Intercept according to the start and end indexes , Get the new string ( Not before, not after )
String name2 = "Java Is the most powerful programming language !";
String rs = name2.substring(0, 9);
System.out.println(rs);
//public String substring(int beginIndex) Intercept from the incoming index , Intercept to the end , Get the new string
String rs1 = name2.substring(4);
System.out.println(rs1);
//public String replace(CharSequence target,CharSequence replacement) Use new value , Replace the old value in the string with , Get the new string
String name3 = " Zhang San is the most powerful 80 after , Zhang sanbang !";
String rs3 = name3.replace(" Zhang San ", "***");
System.out.println(rs3);
//public boolean contains(CharSequence s)
System.out.println(name3.contains(" Zhang San "));//true
System.out.println(name3.contains(" Zhang Er "));//false
//public boolean startsWiths(String prefix)// With "prefix" At the beginning
name3.startsWith(" Zhang San ");//true
//public String[] split(String regex) Cut the string according to the incoming rules , Get string array return
String name4 = " Zhang San , Li Si , Liu Wu ";
String[] names = name4.split(",");
for (int i = 0; i < names.length; i++) {
System.out.println(" I chose :" + names[i]);
}
}
}
边栏推荐
- RTC monthly tabloid programming challenge ended successfully in June; Review of the first anniversary of sound network's listing
- About pickle module - 6 points that beginners must know
- 数据治理市场:亿信华辰朝左,华傲数据向右
- Soap comparison result file description
- 【时序数据库InfluxDB】Windows环境下配置InfluxDB+数据可视化,以及使用 C#进行简单操作的代码实例
- Map reduce case super detailed explanation
- My own opinion on lisp
- Web technology sharing | whiteboard toolbar encapsulation of Web
- Xiao Sha's pain (thinking problem)
- Google Play 索引表
猜你喜欢

ADB devices cannot detect the problem of Xiaomi note 3

Pycharm----xx. So cannot open shared object file problem solving

Three types of technical debt that programmers often encounter: code, data, and architecture

Alibaba cloud OSS object storage cross domain settings

Summary of gradient descent optimizer (rmsprop, momentum, Adam)

Preliminary study on AI noise reduction evaluation system of sound network

Review 2021, embrace change and live up to Shaohua

Create a new MySQL database under Linux and import SQL files
![001 data type [basic]](/img/36/90fdf51a20f8c708b9c38610b377d6.jpg)
001 data type [basic]

Some reference routines for cache update
随机推荐
Don't fight for big companies
Kubernetes: a comprehensive analysis of container choreography
4.4 string
国债逆回购在哪个平台上买比较安全?
【子矩阵数量统计】CF1181C Flag子矩阵数量统计
1058 a+b in Hogwarts (20 points)
4.2 escape characters
4.5 integer
1031 Hello world for u (20 points)
Google Play 索引表
openresty 内置变量
[matlab] 2D drawing summary
Modifying MySQL password under Linux: error 1396 (HY000): Operation alter user failed for 'root' @ 'localhost‘
H - Arctic network (minimum spanning tree)
Abstract meaning
Chapter 2 installation and use of vscode editor
Bye civil engineering, hello CS, can you change the certificate to the Blue Bridge Cup
[ten thousand words long article] thoroughly understand load balancing
Create a new MySQL database under Linux and import SQL files
Review 2021, embrace change and live up to Shaohua