0

How can I replace all the vowels in s1 with z

public class q3 {
    public static void main(String[] args) {

        String s1="Hello World";
        System.out.println(s1.replace("a,e,i,o,u","z"));


    }
}
Abhishek
  • 6,526
  • 13
  • 53
  • 83
Usama
  • 1

1 Answers1

1
System.out.println(s1.replaceAll("[aeiou]", "z"));

If you want to make it case insensitive then use

System.out.println(s1.replaceAll( "(?i)[aeiou]", "z" ));
Abhishek
  • 6,526
  • 13
  • 53
  • 83
Shashiwadana
  • 462
  • 6
  • 13