How to remove specific char from string in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java c c++ python php";
        
        s = s.replaceAll("p", "");
        
        System.out.println(s);
    }
}



/*
run:

java c c++ ython h

*/

 



answered Jul 27, 2020 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "java c c++ python c# php";
        
        char ch = 'p';

        str = str.replaceAll(Character.toString(ch), "");
        
        System.out.print(str);
    }
}
 
 
 
 
 
/*
run:
   
java c c++ ython c# h
   
*/

 



answered Sep 29, 2022 by avibootz

Related questions

1 answer 179 views
1 answer 210 views
1 answer 80 views
1 answer 178 views
2 answers 154 views
1 answer 118 views
1 answer 102 views
...