Consider the following code:
public class Main { private StringBuilder sb = new StringBuilder(); public void logMsg(String location, String message) { sb.append(location);/*ww w .java 2 s.co m*/ sb.append("-"); sb.append(message); } public void dumpLog() { System.out.println(sb.toString()); // Empty the contents of sb here } }
Which of the following options will empty the contents of the StringBuilder referred to by variable sb in method dumpLog()
?
Select 1 option
A. sb.delete (0, sb .length ()); B. sb.clear (); C. sb.empty (); D. sb.removeAll (); E. sb.deleteAll ();
Correct Option is : A
public StringBuilder delete (int start, int end)
Removes the characters in a substring of this sequence.