Are there any ways to Manipulate Strings in Java.

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 09-Feb-2018 14:52:08
Advertisements