Pattern spacePat = Pattern.compile (" ");
StringBuffer sb = new StringBuffer (input);
CharBuffer cb = CharBuffer.wrap (sb.toString());
String [] tokens = null;
try {
System.out.println ("Splitting StringBuffer");
tokens = spacePat.split (sb);
System.out.println ("split OK");
} catch (Exception e) {
System.out.println ("Caught: " + e);
e.printStackTrace();
}
System.out.println ("");
try {
System.out.println ("Splitting CharBuffer");
tokens = spacePat.split (cb);
System.out.println ("split OK");
} catch (Exception e) {
System.out.println ("Caught: " + e);
e.printStackTrace();
}
System.out.println ("");
try {
System.out.println ("Splitting CharBuffer.toString()");
tokens = spacePat.split (cb.toString());
System.out.println ("split OK");
} catch (Exception e) {
System.out.println ("Caught: " + e);
e.printStackTrace();
}