KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > lang > StringBuffer

java.lang
Class StringBuffer

java.lang.Object
  extended by java.lang.StringBuffer
All Implemented Interfaces:
Serializable, Appendable, CharSequence
See Also:
Top Examples, Source Code, StringBuilder, String

public StringBuffer append(boolean b)
See Also:
append(java.lang.String), String.valueOf(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(char c)
See Also:
Appendable, appended, String.valueOf(char)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(char[] str)
See Also:
appended, String.valueOf(char[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(char[] str,
                           int offset,
                           int len)
See Also:
appended, String.valueOf(char[],int,int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(double d)
See Also:
append(java.lang.String), String.valueOf(double)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(float f)
See Also:
append(java.lang.String), String.valueOf(float)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(int i)
See Also:
append(java.lang.String), String.valueOf(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(CharSequence s)
See Also:
Appendable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(CharSequence s,
                           int start,
                           int end)
See Also:
IndexOutOfBoundsException, Appendable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(Object obj)
See Also:
append(java.lang.String), String.valueOf(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(String str)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[20]Growing stringbuffer
By Max Okist on 2003/10/29 10:00:52  Rate
StringBuffer sb = new StringBuffer ( "The" ) ; 
 sb.append ( " StringBuffer" ) ; 
 sb.append ( " is" ) ; 
 sb.append ( " growing" ) ; 
 sb.append ( " with every line of code" ) ;


public StringBuffer append(StringBuffer sb)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer append(long lng)
See Also:
append(java.lang.String), String.valueOf(long)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer appendCodePoint(int codePoint)
See Also:
appended, Character.toChars(int), Character.charCount(codePoint)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int capacity()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public char charAt(int index)
See Also:
length(), IndexOutOfBoundsException, CharSequence
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int codePointAt(int index)
See Also:
length()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1510]Read a file into a stringbuffer
By Anonymous on 2005/08/08 19:18:16  Rate
ArrayList list1=null; 
  
  
 ArrayList list2=null; 
  
  
 FileInputStream in=null; 
  
  
 BufferedReader buff=null; 
  
  
 StringBuffer stBuff= new StringBuffer (  ) ; 
  
  
 Map HMap=new HashMap (  ) ; 
  
  
 Connection connection =null; 
  
  
 // List keys=new ArrayList ( HMap.keySet (  )  ) ; 
  
  
 Iterator iterator= HMap.keySet (  ) .iterator (  ) ; 
  
  
 try 
  
  
  {  
  
  
 in=new FileInputStream ( "C:\\temp\\Input.txt" ) ; 
  
  
 buff=new BufferedReader ( new InputStreamReader ( in )  ) ; 
  
  
 list1=new ArrayList (  ) ; 
  
  
 list2=new ArrayList (  ) ; 
  
  
 int i; 
  
  
 while  ( true )  
  
  
  {  
  
  
 String s=buff.readLine (  ) ; 
  
  
 if ( s==null )  
  
  
  {  
  
  
 break; 
  
  
  }  
  
  
 stBuff.append ( s ) ;  
  
  
  }  
  
  
 // System.out.println ( "Lines in string buffer"+ stBuff ) ; 
  
  
 stBuff.append ( "*" ) ; 
  
  
 System.out.println ( "Lines in string buffer"+ stBuff ) ;


public int codePointBefore(int index)
See Also:
length()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int codePointCount(int beginIndex,
                          int endIndex)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer delete(int start,
                           int end)
See Also:
StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer deleteCharAt(int index)
See Also:
StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[439]Remove a specific character from a stringbuffer
By Anonymous on 2003/10/07 01:32:02  Rate
stk.deleteCharAt (  stk.length (  )  -1  ) ;

public void ensureCapacity(int minimumCapacity)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void getChars(int srcBegin,
                     int srcEnd,
                     char[] dst,
                     int dstBegin)
See Also:
IndexOutOfBoundsException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1719]getChars
By manikaverma_4u { at } yahoo { dot } com on 2006/03/10 08:50:27  Rate
how to use getchars

public int indexOf(String str)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[444]Lets use StringBuffer
By sadik_khan { at } yahoo { dot } com on 2003/10/09 03:53:31  Rate
public String letsUseStringBuffer ( String s )  
      {  
         StringBuffer stringbuffer = new StringBuffer (  ) ; 
         int i = s.lastIndexOf ( "-" ) ; 
         if ( i != -1 )  
             stringbuffer.append ( "Appended this text" ) ; 
         return stringbuffer.toString (  ) ; 
      } 


public int indexOf(String str,
                   int fromIndex)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int offset,
                           boolean b)
See Also:
length(), insert(int, java.lang.String), String.valueOf(boolean), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1131]Insert with Boolean
By aminmc { at } gmail { dot } com on 2004/11/20 04:17:44  Rate
public class InsertWithBoolean  
  {  
      
     public static void main ( String [  ]  args )   
      {  
        boolean flag = false; 
        StringBuffer sb = new StringBuffer ( "Test value: " ) ; 
        sb.insert ( 5, flag ) ; 
        System.out.println  ( sb ) ; 
      }  
      
  }  
  
  
 Prints out: Test falsevalue:


public StringBuffer insert(int offset,
                           char c)
See Also:
length(), IndexOutOfBoundsException, inserted, String.valueOf(char)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int offset,
                           char[] str)
See Also:
StringIndexOutOfBoundsException, inserted, String.valueOf(char[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int index,
                           char[] str,
                           int offset,
                           int len)
See Also:
StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int offset,
                           double d)
See Also:
length(), insert(int, java.lang.String), String.valueOf(double), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int offset,
                           float f)
See Also:
length(), insert(int, java.lang.String), String.valueOf(float), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int offset,
                           int i)
See Also:
length(), insert(int, java.lang.String), String.valueOf(int), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int dstOffset,
                           CharSequence s)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int dstOffset,
                           CharSequence s,
                           int start,
                           int end)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer insert(int offset,
                           Object obj)
See Also:
length(), insert(int, java.lang.String), String.valueOf(java.lang.Object), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[447]Insert into a StringBuffer
By sadik_khan { at } yahoo { dot } com on 2003/10/10 04:40:29  Rate
public String letsUseStringBuffer ( String s )  
      {  
         StringBuffer stringbuffer = new StringBuffer (  ) ; 
         int i = s.lastIndexOf ( "-" ) ; 
         if ( i != -1 )  
             stringbuffer.insert ( i,"This text is inserted at ith position" ) ; 
         return stringbuffer.toString (  ) ; 
      } 


public StringBuffer insert(int offset,
                           String str)
See Also:
length(), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[375]StringBuffer insert and append
By Sandra on 2005/04/15 11:22:27  Rate
observacao.append ( "observ 1" )  
 len = observacao.length (  ) ; 
  
  
 observacao.append ( " observ 2" ) ;  
                  
 for ( int i = len + 1; i  <  93 - observacao.length (  ) ; i++ )  
  { observacao.insert ( i, "-" ) ;  }  
  
  
 out.write ( " < option value='" + "1" + "' > " ) ; 
 out.write ( observacao.toString (  )  ) ; 
 out.write ( " < /option > " ) ;


public StringBuffer insert(int offset,
                           long l)
See Also:
length(), insert(int, java.lang.String), String.valueOf(long), StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int lastIndexOf(String str)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[446]Appending StringBuffer
By sadik_khan { at } yahoo { dot } com on 2003/10/09 04:02:23  Rate
public String letUseStringBuffer ( String s )  
      {  
         StringBuffer stringbuffer = new StringBuffer (  ) ; 
         int i = s.lastIndexOf ( "-" ) ; 
         if ( i != -1 )  
             stringbuffer.append ( "Yes it had - " )  ) ; 
         return stringbuffer.toString (  ) ; 
      } 


public int lastIndexOf(String str,
                       int fromIndex)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int length()
See Also:
CharSequence
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1130]StringBuffer length test
By aminmc { at } gmail { dot } com on 2004/11/20 04:09:04  Rate
public class StringBufferLengthTest 
  {  
      
     public static void main ( String [  ]  args )   
      {  
        StringBuffer sb = new StringBuffer ( "This is my life" ) ; 
        int size = sb.length (  ) ; 
         
        System.out.println  ( "Length of StringBuffer is " + size ) ; 
      }  
      
  }  
 


public int offsetByCodePoints(int index,
                              int codePointOffset)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer replace(int start,
                            int end,
                            String str)
See Also:
StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[445]getR3CharacteristicValue
By sadik_khan { at } yahoo { dot } com on 2005/09/23 16:28:57  Rate
public String getR3CharacteristicValue ( String s )  
      {  
         StringBuffer stringbuffer = new StringBuffer (  ) ; 
         int i = s.lastIndexOf ( "-" ) ; 
         if ( i != -1 )  
             stringbuffer.replace ( i,"I dont need -" ) ; 
             return stringbuffer.toString (  ) ; 
      } 


public StringBuffer reverse()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1129]Reverse a String
By aminmc { at } gmail { dot } com on 2004/11/20 04:06:41  Rate
StringBuffer sb = new StringBuffer ( "My name is Amin" ) ; 
 sb.reverse (  ) ; 
 System.out.println  ( sb ) ; 
  
  
 Output would be: nimA si eman yM


public void setCharAt(int index,
                      char ch)
See Also:
length(), IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setLength(int newLength)
See Also:
length(), IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer(int capacity)
See Also:
NegativeArraySizeException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer(CharSequence seq)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer(String str)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public CharSequence subSequence(int start,
                                int end)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1157]Adds char into a string
By Pedro P??rez on 2004/11/30 05:06:28  Rate
/** 
 * Adds char into a string  
 * */
   
 public static String addCharAfter ( String st, char c, int pos )   
  {  
   String ret =""; 
   if  ( pos  >  0 && pos  < = st.length (  )  )  
    {  
      StringBuffer sb = new StringBuffer ( st ) ; 
      ret =""; 
      ret = sb.subSequence ( 0,pos ) .toString (  )  + c + sb.subSequence ( pos, st.length (  )  ) ; 
    }  
   else 
    {  
     ret = st; 
    }  
   return ret; 
  }  
 


public String substring(int start)
See Also:
StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String substring(int start,
                        int end)
See Also:
StringIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String toString()
See Also:
CharSequence
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void trimToSize()
See Also:
capacity()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags