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,912
  • 14
  • 59
  • 85
Usama
  • 1
  • 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,912
  • 14
  • 59
  • 85
Shashiwadana
  • 492
  • 1
  • 8
  • 16