知识点: substring


public String substring(int beginIndex)返回从起始位置(beginIndex)至字符串末尾的字符串;
public String substring(int beginIndex, int endIndex)返回从起始位置(beginIndex)到目标位置(endIndex)之间的字符串,但不包含目标位置(endIndex)的字符
public class subs {
public static void main(String args[]) {
String Str = new String("m.runoob.com");
System.out.print("返回值 :" );
System.out.println(Str.substring(4) );
System.out.print("返回值 :" );
System.out.println(Str.substring(4, 10) );
}
}
输出:

代码
public class Solution {
public String LeftRotateString(String str, int n) {
if (str == null || n > str.length()) {
return str;
}
return str.substring(n) + str.substring(0, n);
}
}
字符串常见操作
1、子串
substring方法
2、拼接
int age = 13;
String ta = "abc" + age;

3、不可变字符串
String类没有提供修改字符串中某个字符的方法,修改事通过子串加字符串的拼接,例如,将"hello"修改为"help"需要substring(0,3)+“p”.
4、字符串是否相等
s.equal(t);
或
String aa=“abc”
“hello”.equal(aa);
若不区分大小写,则可用equalsIgnoreCase;
“Hello”.equalsIgnoreCase(“hello”);
5、字符串长度
s.length();
6、s.charAt(n)返回位置n的代码
1230

被折叠的 条评论
为什么被折叠?



