for loop to find consonants in a string

后端 未结 5 1024
灰色年华
灰色年华 2021-01-28 02:24

Using a for loop, how do I go about making all consonants in a string uppercase?

I think I should do something like this:

    String str = \"fish$\"             


        
5条回答
  •  后悔当初
    2021-01-28 02:45

    This works for me:

         List constants = Arrays.asList('f', 's', 'h');
         String str = "fish$";
    
         for (Character c : constants) {             
               str = str.replace(c, Character.toUpperCase(c));
          }
    

提交回复
热议问题