当前位置:网站首页>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特训营 第四节 字体设计的重要性

NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元

集群的概述与定义,一看就会

Redis入门完整教程:HyperLogLog

Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore

Logo special training camp section 1 Identification logo and logo design ideas

MySQL Architecture - logical architecture

Detailed explanation of heap sort code

2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { fmt.Pri

The overview and definition of clusters can be seen at a glance
随机推荐
剑指Offer 68 - II. 二叉树的最近公共祖先
业务太忙,真的是没时间搞自动化理由吗?
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
Record: how to scroll screenshots of web pages on Microsoft edge in win10 system?
Gnawing down the big bone - sorting (II)
Redis的持久化机制
MYSQL架构——逻辑架构
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
Alibaba launched a new brand "Lingyang" and is committed to becoming a "digital leader"
浅聊一下中间件
SPSS安装激活教程(包含网盘链接)
Unity-VScode-Emmylua配置报错解决
Advanced area a of attack and defense world misc Masters_ good_ idea
10 schemes to ensure interface data security
LOGO special training camp section I identification logo and Logo Design Ideas
Close system call analysis - Performance Optimization
Prosperity is exhausted, things are right and people are wrong: where should personal webmasters go
LOGO特训营 第二节 文字与图形的搭配关系
Advanced area of attack and defense world misc 3-11
不同环境相同配置项的内容如何diff差异?