No. 1方法名称类型说明
1 publicbooleancontains (字符串)一般判断是否存在指定内容
2公共索引of (字符串)从正常右前到后查找指定字符串的位置,如果找到,返回(第一个字符)位置索引,如果找不到,返回-1
3公共int index of (stringstr,int fromIndex )通常从指定位置向前向后查找指定字符串的位置。 找不到返回-1的位置
4公共int lastindexof (stringstr )通常从后向前查找字符串的位置,但找不到返回-1的结果
5公共int lastindexof (stringstr,int fromIndex )通常从指定位置开始从后向前查找字符串位置,但找不到返回-1的结果
6 publicbooleanstartswith (字符串前缀)通常确定是否以指定字符开头
7 publicbooleanstartswith (string prefix,int toffset )通常从指定的位置开始,判断是否以指定的字符开始
8 publicbooleanendwith (string suffix )通常确定是否以指定字符串结尾
公共类演示{
publicstaticvoidmain (字符串[ ] args ) {
String str=“helloworld”
system.out.println(「world "所在的索引: " str.index of " " world " ) )
System.out.println (“第一个' l '所在的索引: str.indexof )“l”)
System.out.println;
}
}
=====================================
公共类演示{
publicstaticvoidmain (字符串[ ] args ) {
String str=“helloworld”
if(str.contains(「world " ) ) }
System.out.println;
}
}
}
=====================================
公共类演示{
publicstaticvoidmain (字符串[ ] args ) {
stringstr=「@@Hello '; System.out.println ('为@@hello*** ';
System.out.println ('为@@hello ); 是否以System.out.println ('开头: " str.startswith('$$ ' ) "
System.out.println (“在索引为2的位置@ :”str.starts with (“@”,2 ) );
System.out.println;
}
}
标签: Java、String、System、find、str、println、public、out
资料来源: https://blog.csdn.net/weixin _ 42041819/article/details/100176795