Java parenthesis replacement with empty string2019 Community Moderator ElectionReference - What does this...

How could a scammer know the apps on my phone / iTunes account?

Does this property of comaximal ideals always holds?

How can I change step-down my variable input voltage? [Microcontroller]

Brexit - No Deal Rejection

Define, (actually define) the "stability" and "energy" of a compound

An Accountant Seeks the Help of a Mathematician

Know when to turn notes upside-down(eighth notes, sixteen notes, etc.)

Meaning of "SEVERA INDEOVI VAS" from 3rd Century slab

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Why must traveling waves have the same amplitude to form a standing wave?

Current sense amp + op-amp buffer + ADC: Measuring down to 0 with single supply

What are some nice/clever ways to introduce the tonic's dominant seventh chord?

Why do Australian milk farmers need to protest supermarkets' milk price?

Happy pi day, everyone!

Is a lawful good "antagonist" effective?

How to explain that I do not want to visit a country due to personal safety concern?

What are the possible solutions of the given equation?

Latest web browser compatible with Windows 98

Can anyone tell me why this program fails?

Dot in front of file

Rules about breaking the rules. How do I do it well?

Theorems like the Lovász Local Lemma?

How to write cleanly even if my character uses expletive language?

Why are the outputs of printf and std::cout different



Java parenthesis replacement with empty string



2019 Community Moderator ElectionReference - What does this regex mean?What is the difference between String and string in C#?Is Java “pass-by-reference” or “pass-by-value”?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How to split a string in JavaHow do I convert a String to an int in Java?Why is char[] preferred over String for passwords?












6















Why doesn't the first line replace "(" with an empty string , while the second one does?



 public static void main(String []args){
String a="This(rab)(bar)";
a=a.replace("\(",""); //First
String b=a.replaceFirst("\(","");//Second
System.out.println(a + " "+b);
}









share|improve this question







New contributor




Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    6















    Why doesn't the first line replace "(" with an empty string , while the second one does?



     public static void main(String []args){
    String a="This(rab)(bar)";
    a=a.replace("\(",""); //First
    String b=a.replaceFirst("\(","");//Second
    System.out.println(a + " "+b);
    }









    share|improve this question







    New contributor




    Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      6












      6








      6








      Why doesn't the first line replace "(" with an empty string , while the second one does?



       public static void main(String []args){
      String a="This(rab)(bar)";
      a=a.replace("\(",""); //First
      String b=a.replaceFirst("\(","");//Second
      System.out.println(a + " "+b);
      }









      share|improve this question







      New contributor




      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      Why doesn't the first line replace "(" with an empty string , while the second one does?



       public static void main(String []args){
      String a="This(rab)(bar)";
      a=a.replace("\(",""); //First
      String b=a.replaceFirst("\(","");//Second
      System.out.println(a + " "+b);
      }






      java string replace






      share|improve this question







      New contributor




      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Mar 10 at 9:12









      Erik NouroyanErik Nouroyan

      342




      342




      New contributor




      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Erik Nouroyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          3 Answers
          3






          active

          oldest

          votes


















          4














          There is a difference between replace and replaceFirst. If your IDE shows you the method signatures, you'll see:



          enter image description here



          See how replace accepts a plain old target whereas replaceFirst accepts a regex?



          "\(" is a regex that means "a single open parenthesis". replace doesn't treat the strings you pass in as regexes. It will simply try to find a backslash followed by an open parenthesis, which does not exist in your string.



          If you want to use replace, just use "(".






          share|improve this answer
























          • So isn't this "(" a regex? It's a string isn't it?

            – Erik Nouroyan
            Mar 10 at 9:23











          • @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

            – Sweeper
            Mar 10 at 9:28











          • why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

            – Erik Nouroyan
            Mar 10 at 9:30













          • Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

            – Sweeper
            Mar 10 at 9:33






          • 1





            stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

            – Sweeper
            Mar 10 at 9:37



















          3














          For replace to work you should write:



          a=a.replace("(",""); //First


          or use replaceAll if you want to pass a regex:



          a=a.replaceAll("\(",""); //First


          replace accepts a sequence of characters to replace:



          public String replace(CharSequence target, CharSequence replacement)


          Therefore, in your case it attempts to replace the 3 characters "(", not just the single character "(".






          share|improve this answer


























          • In that case why doesn't this work? a=a.replace("(",""); //First

            – Erik Nouroyan
            Mar 10 at 9:17











          • @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

            – Eran
            Mar 10 at 9:18





















          0














          The problem is that it is running in replace with several characters and, therefore, what it will look for is and (, so that this does not happen the quotation marks should only contain the character to replace :



              a = a.replace("(", ""); // First


          Next I leave a sniper with the original proposal and the fixed one :



          public class Main {

          private static final Main initRun = new Main();

          public static void main(String[] args) {

          String a = "This(rab)(bar)";

          System.out.println("Original");
          initRun.runOriginal(a);

          System.out.println("Fixed");
          initRun.runFixed(a);

          // Output
          // Original
          // This(rab)(bar)
          // Thisrab)(bar)
          // Fixed
          // Thisrab)bar)
          // Thisrab)bar)
          }

          /**
          * Execute the original proposal
          *
          * @param a String for replace
          */
          void runOriginal(String a) {
          a = a.replace("\(", ""); // First
          String b = a.replaceFirst("\(", "");// Second
          System.out.println(a + "n" + b);
          }

          /**
          * Execute the fixed proposal
          *
          * @param a String for replace
          */
          void runFixed(String a) {

          a = a.replace("(", ""); // First
          String b = a.replaceFirst("\(", "");// Second
          System.out.println(a + "n" + b);
          }
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Erik Nouroyan is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55086135%2fjava-parenthesis-replacement-with-empty-string%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            There is a difference between replace and replaceFirst. If your IDE shows you the method signatures, you'll see:



            enter image description here



            See how replace accepts a plain old target whereas replaceFirst accepts a regex?



            "\(" is a regex that means "a single open parenthesis". replace doesn't treat the strings you pass in as regexes. It will simply try to find a backslash followed by an open parenthesis, which does not exist in your string.



            If you want to use replace, just use "(".






            share|improve this answer
























            • So isn't this "(" a regex? It's a string isn't it?

              – Erik Nouroyan
              Mar 10 at 9:23











            • @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

              – Sweeper
              Mar 10 at 9:28











            • why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

              – Erik Nouroyan
              Mar 10 at 9:30













            • Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:33






            • 1





              stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:37
















            4














            There is a difference between replace and replaceFirst. If your IDE shows you the method signatures, you'll see:



            enter image description here



            See how replace accepts a plain old target whereas replaceFirst accepts a regex?



            "\(" is a regex that means "a single open parenthesis". replace doesn't treat the strings you pass in as regexes. It will simply try to find a backslash followed by an open parenthesis, which does not exist in your string.



            If you want to use replace, just use "(".






            share|improve this answer
























            • So isn't this "(" a regex? It's a string isn't it?

              – Erik Nouroyan
              Mar 10 at 9:23











            • @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

              – Sweeper
              Mar 10 at 9:28











            • why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

              – Erik Nouroyan
              Mar 10 at 9:30













            • Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:33






            • 1





              stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:37














            4












            4








            4







            There is a difference between replace and replaceFirst. If your IDE shows you the method signatures, you'll see:



            enter image description here



            See how replace accepts a plain old target whereas replaceFirst accepts a regex?



            "\(" is a regex that means "a single open parenthesis". replace doesn't treat the strings you pass in as regexes. It will simply try to find a backslash followed by an open parenthesis, which does not exist in your string.



            If you want to use replace, just use "(".






            share|improve this answer













            There is a difference between replace and replaceFirst. If your IDE shows you the method signatures, you'll see:



            enter image description here



            See how replace accepts a plain old target whereas replaceFirst accepts a regex?



            "\(" is a regex that means "a single open parenthesis". replace doesn't treat the strings you pass in as regexes. It will simply try to find a backslash followed by an open parenthesis, which does not exist in your string.



            If you want to use replace, just use "(".







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 10 at 9:16









            SweeperSweeper

            70k1074142




            70k1074142













            • So isn't this "(" a regex? It's a string isn't it?

              – Erik Nouroyan
              Mar 10 at 9:23











            • @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

              – Sweeper
              Mar 10 at 9:28











            • why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

              – Erik Nouroyan
              Mar 10 at 9:30













            • Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:33






            • 1





              stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:37



















            • So isn't this "(" a regex? It's a string isn't it?

              – Erik Nouroyan
              Mar 10 at 9:23











            • @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

              – Sweeper
              Mar 10 at 9:28











            • why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

              – Erik Nouroyan
              Mar 10 at 9:30













            • Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:33






            • 1





              stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

              – Sweeper
              Mar 10 at 9:37

















            So isn't this "(" a regex? It's a string isn't it?

            – Erik Nouroyan
            Mar 10 at 9:23





            So isn't this "(" a regex? It's a string isn't it?

            – Erik Nouroyan
            Mar 10 at 9:23













            @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

            – Sweeper
            Mar 10 at 9:28





            @ErikNouroyan ( is not a valid regex. It doesn’t mean “match an open parenthesis”. ( is valid regex that means “Match an open parenthesis”. In java string literals, the backslash gets escapes to become ``.

            – Sweeper
            Mar 10 at 9:28













            why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

            – Erik Nouroyan
            Mar 10 at 9:30







            why does replaceFirst take "\( " as a single paranthesis insted of backslash and single paranthesis?

            – Erik Nouroyan
            Mar 10 at 9:30















            Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

            – Sweeper
            Mar 10 at 9:33





            Because ( is a regex that means “one opening parenthesis” and replaceFirst accepts a regex. ( on its own has special meaning in regex - start of a capturing group, so you need to escape it with `` to mean “one open parenthesis”. @ErikNouroyan

            – Sweeper
            Mar 10 at 9:33




            1




            1





            stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

            – Sweeper
            Mar 10 at 9:37





            stackoverflow.com/a/22944075/5133585 might help. @ErikNouroyan

            – Sweeper
            Mar 10 at 9:37













            3














            For replace to work you should write:



            a=a.replace("(",""); //First


            or use replaceAll if you want to pass a regex:



            a=a.replaceAll("\(",""); //First


            replace accepts a sequence of characters to replace:



            public String replace(CharSequence target, CharSequence replacement)


            Therefore, in your case it attempts to replace the 3 characters "(", not just the single character "(".






            share|improve this answer


























            • In that case why doesn't this work? a=a.replace("(",""); //First

              – Erik Nouroyan
              Mar 10 at 9:17











            • @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

              – Eran
              Mar 10 at 9:18


















            3














            For replace to work you should write:



            a=a.replace("(",""); //First


            or use replaceAll if you want to pass a regex:



            a=a.replaceAll("\(",""); //First


            replace accepts a sequence of characters to replace:



            public String replace(CharSequence target, CharSequence replacement)


            Therefore, in your case it attempts to replace the 3 characters "(", not just the single character "(".






            share|improve this answer


























            • In that case why doesn't this work? a=a.replace("(",""); //First

              – Erik Nouroyan
              Mar 10 at 9:17











            • @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

              – Eran
              Mar 10 at 9:18
















            3












            3








            3







            For replace to work you should write:



            a=a.replace("(",""); //First


            or use replaceAll if you want to pass a regex:



            a=a.replaceAll("\(",""); //First


            replace accepts a sequence of characters to replace:



            public String replace(CharSequence target, CharSequence replacement)


            Therefore, in your case it attempts to replace the 3 characters "(", not just the single character "(".






            share|improve this answer















            For replace to work you should write:



            a=a.replace("(",""); //First


            or use replaceAll if you want to pass a regex:



            a=a.replaceAll("\(",""); //First


            replace accepts a sequence of characters to replace:



            public String replace(CharSequence target, CharSequence replacement)


            Therefore, in your case it attempts to replace the 3 characters "(", not just the single character "(".







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 10 at 9:17

























            answered Mar 10 at 9:16









            EranEran

            288k37471561




            288k37471561













            • In that case why doesn't this work? a=a.replace("(",""); //First

              – Erik Nouroyan
              Mar 10 at 9:17











            • @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

              – Eran
              Mar 10 at 9:18





















            • In that case why doesn't this work? a=a.replace("(",""); //First

              – Erik Nouroyan
              Mar 10 at 9:17











            • @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

              – Eran
              Mar 10 at 9:18



















            In that case why doesn't this work? a=a.replace("(",""); //First

            – Erik Nouroyan
            Mar 10 at 9:17





            In that case why doesn't this work? a=a.replace("(",""); //First

            – Erik Nouroyan
            Mar 10 at 9:17













            @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

            – Eran
            Mar 10 at 9:18







            @ErikNouroyan replace does not expect a regex as the first argument. Therefore it tried to replace the actual sub-string "\(", which is not present in a.

            – Eran
            Mar 10 at 9:18













            0














            The problem is that it is running in replace with several characters and, therefore, what it will look for is and (, so that this does not happen the quotation marks should only contain the character to replace :



                a = a.replace("(", ""); // First


            Next I leave a sniper with the original proposal and the fixed one :



            public class Main {

            private static final Main initRun = new Main();

            public static void main(String[] args) {

            String a = "This(rab)(bar)";

            System.out.println("Original");
            initRun.runOriginal(a);

            System.out.println("Fixed");
            initRun.runFixed(a);

            // Output
            // Original
            // This(rab)(bar)
            // Thisrab)(bar)
            // Fixed
            // Thisrab)bar)
            // Thisrab)bar)
            }

            /**
            * Execute the original proposal
            *
            * @param a String for replace
            */
            void runOriginal(String a) {
            a = a.replace("\(", ""); // First
            String b = a.replaceFirst("\(", "");// Second
            System.out.println(a + "n" + b);
            }

            /**
            * Execute the fixed proposal
            *
            * @param a String for replace
            */
            void runFixed(String a) {

            a = a.replace("(", ""); // First
            String b = a.replaceFirst("\(", "");// Second
            System.out.println(a + "n" + b);
            }
            }





            share|improve this answer




























              0














              The problem is that it is running in replace with several characters and, therefore, what it will look for is and (, so that this does not happen the quotation marks should only contain the character to replace :



                  a = a.replace("(", ""); // First


              Next I leave a sniper with the original proposal and the fixed one :



              public class Main {

              private static final Main initRun = new Main();

              public static void main(String[] args) {

              String a = "This(rab)(bar)";

              System.out.println("Original");
              initRun.runOriginal(a);

              System.out.println("Fixed");
              initRun.runFixed(a);

              // Output
              // Original
              // This(rab)(bar)
              // Thisrab)(bar)
              // Fixed
              // Thisrab)bar)
              // Thisrab)bar)
              }

              /**
              * Execute the original proposal
              *
              * @param a String for replace
              */
              void runOriginal(String a) {
              a = a.replace("\(", ""); // First
              String b = a.replaceFirst("\(", "");// Second
              System.out.println(a + "n" + b);
              }

              /**
              * Execute the fixed proposal
              *
              * @param a String for replace
              */
              void runFixed(String a) {

              a = a.replace("(", ""); // First
              String b = a.replaceFirst("\(", "");// Second
              System.out.println(a + "n" + b);
              }
              }





              share|improve this answer


























                0












                0








                0







                The problem is that it is running in replace with several characters and, therefore, what it will look for is and (, so that this does not happen the quotation marks should only contain the character to replace :



                    a = a.replace("(", ""); // First


                Next I leave a sniper with the original proposal and the fixed one :



                public class Main {

                private static final Main initRun = new Main();

                public static void main(String[] args) {

                String a = "This(rab)(bar)";

                System.out.println("Original");
                initRun.runOriginal(a);

                System.out.println("Fixed");
                initRun.runFixed(a);

                // Output
                // Original
                // This(rab)(bar)
                // Thisrab)(bar)
                // Fixed
                // Thisrab)bar)
                // Thisrab)bar)
                }

                /**
                * Execute the original proposal
                *
                * @param a String for replace
                */
                void runOriginal(String a) {
                a = a.replace("\(", ""); // First
                String b = a.replaceFirst("\(", "");// Second
                System.out.println(a + "n" + b);
                }

                /**
                * Execute the fixed proposal
                *
                * @param a String for replace
                */
                void runFixed(String a) {

                a = a.replace("(", ""); // First
                String b = a.replaceFirst("\(", "");// Second
                System.out.println(a + "n" + b);
                }
                }





                share|improve this answer













                The problem is that it is running in replace with several characters and, therefore, what it will look for is and (, so that this does not happen the quotation marks should only contain the character to replace :



                    a = a.replace("(", ""); // First


                Next I leave a sniper with the original proposal and the fixed one :



                public class Main {

                private static final Main initRun = new Main();

                public static void main(String[] args) {

                String a = "This(rab)(bar)";

                System.out.println("Original");
                initRun.runOriginal(a);

                System.out.println("Fixed");
                initRun.runFixed(a);

                // Output
                // Original
                // This(rab)(bar)
                // Thisrab)(bar)
                // Fixed
                // Thisrab)bar)
                // Thisrab)bar)
                }

                /**
                * Execute the original proposal
                *
                * @param a String for replace
                */
                void runOriginal(String a) {
                a = a.replace("\(", ""); // First
                String b = a.replaceFirst("\(", "");// Second
                System.out.println(a + "n" + b);
                }

                /**
                * Execute the fixed proposal
                *
                * @param a String for replace
                */
                void runFixed(String a) {

                a = a.replace("(", ""); // First
                String b = a.replaceFirst("\(", "");// Second
                System.out.println(a + "n" + b);
                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 10 at 9:52









                Nicolás Alarcón RapelaNicolás Alarcón Rapela

                1,164624




                1,164624






















                    Erik Nouroyan is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Erik Nouroyan is a new contributor. Be nice, and check out our Code of Conduct.













                    Erik Nouroyan is a new contributor. Be nice, and check out our Code of Conduct.












                    Erik Nouroyan is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55086135%2fjava-parenthesis-replacement-with-empty-string%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Magento 2 - Add success message with knockout Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Success / Error message on ajax request$.widget is not a function when loading a homepage after add custom jQuery on custom themeHow can bind jQuery to current document in Magento 2 When template load by ajaxRedirect page using plugin in Magento 2Magento 2 - Update quantity and totals of cart page without page reload?Magento 2: Quote data not loaded on knockout checkoutMagento 2 : I need to change add to cart success message after adding product into cart through pluginMagento 2.2.5 How to add additional products to cart from new checkout step?Magento 2 Add error/success message with knockoutCan't validate Post Code on checkout page

                    Fil:Tokke komm.svg

                    Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?