Sunday, August 15, 2010

StringBuilder: Mutate.java

Courtesy of Sun Web Learning Center


1. class Mutate {
2.   public static void main(String [] args) {
3.     StringBuilder s = new StringBuilder("012345678 ");
4.     if (s.length() == 10)
5.       s.insert(10, "abcdef");
6.     s.delete(3,8);
7.     System.out.println(s.indexOf("c"));
8.   }
9. }

What is the result?

A     -1
B     5
C     6
D     7
E     Compilation fails.
F     An exception is thrown at runtime.

No comments:

Post a Comment