How to replace a few characters at ones in a String in Java

1 Answer

0 votes
package javaapplication1;


public class JavaApplication1 {
 
    public static void main(String[] args) {
         
        String s = "-[1, 2, 3, 4, 5, 6, 7]-";
        s = s.replaceAll(", ", " ").replace("[", "").replace("]", "").replace("-", "");
        System.out.println(s);
    }
}
 
/*
 
run:
 
1 2 3 4 5 6 7
 
*/

 



answered Oct 22, 2016 by avibootz

Related questions

4 answers 350 views
2 answers 202 views
1 answer 184 views
1 answer 212 views
1 answer 154 views
...