当前位置:网站首页>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
边栏推荐
- 业务太忙,真的是没时间搞自动化理由吗?
- NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元
- leetcode 72. Edit distance edit distance (medium)
- Interview essential leetcode linked list algorithm question summary, whole process dry goods!
- [Lua] Int64 support
- Prosperity is exhausted, things are right and people are wrong: where should personal webmasters go
- Domestic database chaos
- 浅聊一下中间件
- Li Kou 98: verify binary search tree
- SPSS installation and activation tutorial (including network disk link)
猜你喜欢
Logo special training camp section III initial creative techniques
集群的概述与定义,一看就会
MYSQL架构——用户权限与管理
Mongodb aggregation operation summary
It is said that software testing is very simple, but why are there so many dissuasions?
攻防世界 MISC 进阶区 hong
Attack and defense world misc advanced area can_ has_ stdio?
Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
Redis入门完整教程:发布订阅
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
随机推荐
LOGO特训营 第二节 文字与图形的搭配关系
Create Ca and issue certificate through go language
Sobel filter
Introducing QA into the software development lifecycle is the best practice that engineers should follow
关于栈区、堆区、全局区、文字常量区、程序代码区
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
Business is too busy. Is there really no reason to have time for automation?
LOGO special training camp section I identification logo and Logo Design Ideas
Challenges faced by virtual human industry
蓝队攻防演练中的三段作战
UML图记忆技巧
常用技术指标之一文读懂BOLL布林线指标
Attack and defense world misc advanced area can_ has_ stdio?
POM in idea XML dependency cannot be imported
【lua】int64的支持
Li Kou 98: verify binary search tree
都说软件测试很简单有手就行,但为何仍有这么多劝退的?
leetcode 72. Edit distance edit distance (medium)
SPSS installation and activation tutorial (including network disk link)
Serial port data frame