Are there any ways to Manipulate Strings in Java.


Since String class is immutable once created we cannot modify the data of the string. But still, if you want to manipulate string data you can rely on StringBuffer or StringBuilder classes.

Example

public class Test {
   public static void main(String args[]) {
      String str = "Hi welcome ";
      StringBuffer sb= new StringBuffer(str);
      sb.append("to Tutorialspoint");
      System.out.println(sb);
   }
}

Output

Hi welcome to Tutorialspoint

Updated on: 26-Feb-2020

98 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements