deleteCharAt
StringBuilder deleteCharAt(int index)
- Removes the char at the specified position in this sequence.
public class Main {
public static void main(String[] argv) {
StringBuilder sb = new StringBuilder();
sb.append("java2s.com");
sb.deleteCharAt(0);
System.out.println(sb.toString());
}
}
The output:
ava2s.com
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.
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
StringBuilder insert(int offset, boolean b)
- Inserts the string representation of the boolean argument into this sequence.
StringBuilder insert(int offset, char c)
- Inserts the string representation of the char argument into this sequence.
StringBuilder insert(int offset, char[] str)
- Inserts the string representation of the char array argument into this sequence.
StringBuilder insert(int index, char[] str, int offset, int len)
- Inserts the string representation of a subarray of the str array argument into this sequence.
StringBuilder insert(int dstOffset, CharSequence s)
- Inserts the specified CharSequence into this sequence.
StringBuilder insert(int dstOffset, CharSequence s, int start, int end)
- Inserts a subsequence of the specified CharSequence into this sequence.
StringBuilder insert(int offset, double d)
- Inserts the string representation of the double argument into this sequence.
StringBuilder insert(int offset, float f)
- Inserts the string representation of the float argument into this sequence.
StringBuilder insert(int offset, int i)
- Inserts the string representation of the second int argument into this sequence.
StringBuilder insert(int offset, long l)
- Inserts the string representation of the long argument into this sequence.
StringBuilder insert(int offset, Object obj)
- Inserts the string representation of the Object argument into this character sequence.
StringBuilder insert(int offset, String str)
- Inserts the string into this character sequence.
public class Main {
public static void main(String[] a) {
StringBuilder builder = new StringBuilder("Line 1\n");
builder.append("Line 3\n");
String lineToInsert = "Line 2\n";
builder.insert(0, lineToInsert);
System.out.println(builder.toString());
}
}
Output:
Line 2
Line 1
Line 3
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