Return | Method | Summary |
---|---|---|
int | indexOf(String str) | Returns the index within this string of the first occurrence of the specified substring. |
int | indexOf(String str, int fromIndex) | Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. |
int | lastIndexOf(String str) | Returns the index within this string of the rightmost occurrence of the specified substring. |
int | lastIndexOf(String str, int fromIndex) | Returns the index within this string of the last occurrence of the specified substring. |
public class Main {
public static void main(String[] argv) {
StringBuilder sb = new StringBuilder();
sb.append("java2s.com");
int index = sb.indexOf("com");
System.out.println(index);
}
}
The output:
7
public class Main {
public static void main(String[] argv) {
StringBuilder sb = new StringBuilder();
sb.append("java2s.com");
sb.append(123);
sb.append(1.23);
sb.append(true);
sb.insert(4,"JAVA2S.COM");
System.out.println(sb.toString());
}
}
The output:
javaJAVA2S.COM2s.com1231.23true
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |