当前位置:网站首页>Common methods in string class
Common methods in string class
2022-07-04 22:50:00 【crazyK.】
Method
charAt(int index) | return char Specify the value at the index . |
---|---|
codePointAt(int index) | Returns the character at the specified index (Unicode Code points ) |
codePointBefore(int index) | Returns the characters before the specified index (Unicode Code points ). |
concat(String str) | Connect the specified string to the end of the string . |
contains(CharSequence s) | If and only if the string contains the specified char Value sequence true. |
endsWith(String suffix) | Tests whether the string ends with the specified suffix . |
equals(Object anObject) | Compare this string with the specified object . |
hashCode() | Returns the hash code of this string |
indexOf(String str, int fromIndex) | Returns the index within the string of the first occurrence of the specified substring , Start the search with the specified index . formIndex Can not pass |
isEmpty() | return true If , And only if length() by 0 . |
lastIndexOf(String str, int fromIndex) | Returns the index of the last occurrence of the specified substring , Search backwards from the specified index . formIndex Can not pass |
length() | Returns the length of this string |
replace(char oldChar, char newChar) | Returns a string that results from replacing all occurrences oldChar In this string newChar |
replace(CharSequence target, CharSequence replacement) | Replaces each substring of the string that matches the literal target sequence with the specified literal replacement sequence . |
split(String regex) | Splits this string into the given regular expression Of matching . |
startsWith(String prefix) | Tests whether the string starts with the specified prefix . |
substring(int beginIndex, int endIndex) | Returns a string , This string is a substring of this string . endIndex Can not pass |
toCharArray() | Convert this string to a new character array . |
toLowerCase() | Put all characters here String Rules for using the default locale , In lowercase . |
toUpperCase() | Put all characters here String Use the default locale's rules for capitalization . |
Use samples
public class StringTest {
private static String str = "1,a,2,b,3,c";
public static void main(String[] args) {
System.out.println("charAt: "+ str.charAt(0));
System.out.println("codePointAt: " + str.codePointAt(0));
System.out.println("codePointBefore: " + str.codePointBefore(3));
System.out.println("concat: " + str.concat(","));
System.out.println("contains: " + str.contains(","));
System.out.println("endsWith: " + str.endsWith(","));
System.out.println("equals: " + str.equals("ss"));
System.out.println("hashCode: " + str.hashCode());
System.out.println("indexOf: " + str.indexOf(",", 2));
System.out.println("isEmpty: " + str.isEmpty());
System.out.println("lastIndexOf: " + str.lastIndexOf(","));
System.out.println("length: " + str.length());
System.out.println("replace1: " + str.replace("a", "A"));
System.out.println("replace2: " + str.replace("a,2,b", "A,2,B"));
String[] split = str.split(",");
for (String s : split) {
System.out.print(s);
}
System.out.println();
System.out.println("startsWith: " + str.startsWith("1"));
System.out.println("substring: " + str.substring(3, 5));
char[] chars = str.toCharArray();
for (char aChar : chars) {
System.out.print(aChar);
}
System.out.println();
System.out.println("toUpperCase: " + str.toUpperCase());
System.out.println("toLowerCase: " + str.toUpperCase().toLowerCase());
}
}
Console printing
charAt: 1
codePointAt: 49
codePointBefore: 97
concat: 1,a,2,b,3,c,
contains: true
endsWith: false
equals: false
hashCode: 713949408
indexOf: 3
isEmpty: false
lastIndexOf: 9
length: 11
replace1: 1,A,2,b,3,c
replace2: 1,A,2,B,3,c
1a2b3c
startsWith: true
substring: ,2
1,a,2,b,3,c
toUpperCase: 1,A,2,B,3,C
toLowerCase: 1,a,2,b,3,c
边栏推荐
- Logo special training camp Section IV importance of font design
- Unity vscode emmylua configuration error resolution
- The overview and definition of clusters can be seen at a glance
- MySQL Architecture - logical architecture
- 9 - 类
- MySQL Architecture - user rights and management
- Flask 上下文详解
- How to send a reliable request before closing the page
- Persistence mechanism of redis
- Erik baleog and Olaf, advanced area of misc in the attack and defense world
猜你喜欢
NFT insider 64: e-commerce giant eBay submitted an NFT related trademark application, and KPMG will invest $30million in Web3 and metauniverse
More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?
Install the gold warehouse database of NPC
LOGO special training camp section I identification logo and Logo Design Ideas
攻防世界 misc 高手进阶区 a_good_idea
集群的概述与定义,一看就会
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
On-off and on-off of quality system construction
Logo Camp d'entraînement section 3 techniques créatives initiales
Logo special training camp section II collocation relationship between words and graphics
随机推荐
Redis入门完整教程:客户端通信协议
Microservices -- Opening
MYSQL架构——用户权限与管理
Business is too busy. Is there really no reason to have time for automation?
The sandbox has reached a cooperation with digital Hollywood to accelerate the economic development of creators through human resource development
Summary of index operations in mongodb
How diff are the contents of the same configuration item in different environments?
MYSQL架构——逻辑架构
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Challenges faced by virtual human industry
Tla+ introductory tutorial (1): introduction to formal methods
LOGO特训营 第三节 首字母创意手法
记录:关于Win10系统中Microsoft Edge上的网页如何滚动截屏?
Logo special training camp section 1 Identification logo and logo design ideas
Recommendation of mobile app for making barcode
安装人大金仓数据库
Now MySQL cdc2.1 is parsing the datetime class with a value of 0000-00-00 00:00:00
Attack and defense world misc advanced grace-50
SPSS installation and activation tutorial (including network disk link)
UML diagram memory skills