How to replace all square brackets in a string with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "[c c++] [c# java python] [php javascript]";

        str = str.replaceAll("\\[", "*").replaceAll("\\]","*");
 
        System.out.println(str);
    }
}




/*
run:

*c c++* *c# java python* *php javascript*

*/

 



answered Sep 9, 2023 by avibootz

Related questions

...