Convert StringBuffer to String

ReturnMethodSummary
Stringsubstring(int start)Returns a new String that contains a subsequence of characters currently contained in this character sequence.
Stringsubstring(int start, int end)Returns a new String that contains a subsequence of characters currently contained in this sequence.
StringtoString()Returns a string representing the data in this sequence.
CharSequencesubSequence(int start, int end)Returns a new character sequence that is a subsequence of this sequence.

public class Main {
  public static void main(String[] argv) {
    StringBuffer sb = new StringBuffer();
    sb.append("java2s.com");
    
    int index = sb.indexOf("com");
    
    System.out.println(index);

  }
}

The output:


7
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.