当前位置:网站首页>String中常用的API
String中常用的API
2022-07-28 17:55:00 【剑小麟】
1.length() 表示长度 charAt(i)表示指出某个位置的字符
代码示例如下:
public class Capi {
public static void main(String[] args) {
String name="我爱java";
System.out.println(name.length());//长度
System.out.println(name.charAt(1));//某位置字符
}
}运行结果如下:

2. substring(x,y) 表示截取字段 xy分别表示需要进行的起始和末尾位置
substring(z) 表示从当前位置截取到最后
代码示例如下:
public class Capi {
public static void main(String[] args) {
String name2="我爱java哈哈哈";
System.out.println(name2.substring(0, 6));//截取字段 起始和末尾
System.out.println(name2.substring(5));//当前位置截取到最后
}
}运行结果如下:

3.replace("a","b") 将该字符串中的a替换为b
contains("c") 是否有c字符串
startsWith("d") d字符串是否为开头
代码示例如下:
public class Capi {
public static void main(String[] args) {
String name3="我爱java哈哈哈";
String st=name3.replace("哈哈哈","***");
System.out.println(name3.contains("java"));//是否有该字符段
System.out.println(name3.startsWith("我"));//该字符是否为开头
}
}运行结果如下:

边栏推荐
- MATLAB实现的图像分割之边缘检测和连接
- In order to develop high-end photoresist, Jingrui Co., Ltd. invested 75million yuan to purchase SK Hynix ASML lithography machine
- C language cycle sentence strengthening exercises
- 这个客制化键盘,秀翻我了~
- SaltStack进阶
- Left alignment function of Lua language (handwriting)
- redis 主从架构(sizeof函数怎么计算)
- After reading the thesis for three years, I learned to read the abstract today
- Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization
- 英文翻译葡萄牙语-批量英文转换葡萄牙语-各种语言免费互译转换
猜你喜欢

Sword finger offer II 109. unlock the password lock

Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization

Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)

Rust Getting Started Guide (modules and engineering structures)

Pytoch: implementation of crossentropyloss and labelsmoothing

WPF 实现带蒙版的 MessageBox 消息提示框

WPF implements MessageBox message prompt box with mask

MATLAB实现的图像分割之边缘检测和连接

idea properties文件显示\u不显示中文的解决

Rust 入门指南(rustup, cargo)
随机推荐
远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
First blog
adb remount of the / superblock failed: Permission denied
Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
After reading the thesis for three years, I learned to read the abstract today
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network
How does app automated testing achieve H5 testing
你知道雨的类型有几种?
亚马逊推出Amazon One手掌支付系统,非接触式掌静脉识别市场有望爆发
OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)
Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
Force buckle 1331. Array serial number conversion
Using Baidu easydl to realize chef hat recognition of bright kitchen and stove
Business visualization - let your flowchart "run" (4. Actual business scenario test)
Basic concept and essence of Architecture
博途1200/1500PLC上升沿下降沿指令编程应用技巧(bool数组)
Taking the opportunity of digital transformation, how can 3C enterprises achieve efficient collaboration through SRM supplier cloud collaboration platform?
MySQL8 基于clone创建主从复制