❮ Previous Next ❯

Conversion from String to StringBuffer and StringBuilder

Here in this context We can directly pass String class object to StringBuffer and StringBuilder class constructors. As String class is immutable in java, so for editing a string, we can perform same by converting it to StringBuffer or StringBuilder class objects.

Example.java

public class Example
{
      public static void main(String[] args)
      {
      String str="SILAN";
      //Conversion from String object to StringBuffer
      StringBuffer sb1=new StringBuffer(str);
      System.out.println(sb1);
      sb1.reverse();
      System.out.println(sb1);
      //Conversion from String object to StringBuilder
      StringBuilder sb2=new StringBuilder(str);
      sb2.append("Technology");
      System.out.println(sb2);
      }
}

Output:

SILAN

NALIS

SILANTechnology


❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved