replace all square brackets in a string java regex

public class Main
{
	public static void main(String[] args) {
		String str = "[This is a] [Test String]";
		System.out.println("String with square brackets: " + str);
 
        str = str.replaceAll("\\[", "").replaceAll("\\]","");
 
        System.out.println("String after square brackets: " + str);
	}
}

Output:

String with square brackets: [This is a] [Test String]
String after square brackets: This is a Test String
Content Protection by DMCA.com
Please Share