How can I invert the case of a String in Java?

后端 未结 9 1414
感情败类
感情败类 2020-11-30 12:16

I want to change a String so that all the uppercase characters become lowercase, and all the lower case characters become uppercase. Number characters are just ignored.

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 13:16

    Based on Faraz's approach, I think the character conversion can be as simple as:

    t += Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);
    

提交回复
热议问题