PROGRAM FOR REPLACE TO STRING.

This is the programe for replacing one string by another string using replace method in programe.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.io.*;
public class ReplaceStr
{
       public static void main(String[] args)throws IOException
       {
           BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
           System.out.println("Enter First String:");
           String str1 = bf.readLine();
           System.out.println("Enter second String:");
           String str2 = bf.readLine();
           String com = str2.replace("str1","");
           System.out.println("Replace with first string: " + com);
      }
}

 

Output :Replace String
binary