当前位置:网站首页>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
边栏推荐
- Test will: bug classification and promotion solution
- How to manage 15million employees easily?
- Serial port data frame
- Attack and defense world misc advanced area Hong
- Logo special training camp section 1 Identification logo and logo design ideas
- [cooking record] - stir fried 1000 pieces of green pepper
- Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- Easy to use app recommendation: scan QR code, scan barcode and view history
- NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元
猜你喜欢
Close system call analysis - Performance Optimization
Logo special training camp Section V font structure and common design techniques
MYSQL架构——用户权限与管理
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
PMO: compare the sample efficiency of 25 molecular optimization methods
Advanced area a of attack and defense world misc Masters_ good_ idea
攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
Attack and defense world misc advanced grace-50
随机推荐
Serial port data frame
Redis入门完整教程:客户端通信协议
模拟摇杆控制舵机
【烹饪记录】--- 青椒炒千张
POM in idea XML dependency cannot be imported
PostgreSQL server programming aggregation and grouping
Close system call analysis - Performance Optimization
Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?
Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
LOGO特训营 第三节 首字母创意手法
NFT insider 64: e-commerce giant eBay submitted an NFT related trademark application, and KPMG will invest $30million in Web3 and metauniverse
Now MySQL cdc2.1 is parsing the datetime class with a value of 0000-00-00 00:00:00
9 - class
Challenges faced by virtual human industry
Logo special training camp section 1 Identification logo and logo design ideas
Three stage operations in the attack and defense drill of the blue team
It is said that software testing is very simple, but why are there so many dissuasions?
Detailed explanation of heap sort code
剑指 Offer 65. 不用加减乘除做加法
【OpenGL】笔记二十九、抗锯齿(MSAA)