简单的将驼峰命名变量转化为多个单词组成的变量名的方法

来源:互联网 发布:java主流技术 编辑:程序博客网 时间:2024/06/05 09:29

将一个驼峰命名转换成由多个单词组成的变量名的变量名:例如:将helloWorld转换成hello_world

public class Client {    public static String toHump(String str) {        String rs = "";        for (int i = 0; i < str.length(); i++) {            char c = str.charAt(i);            if (Character.isUpperCase(c)) {                rs += "_" + Character.toLowerCase(c);            } else {                rs += c;            }        }        return rs;    }    public static void main(String[] args) {        String str = "helloWorld"; // hello_world        System.out.println(toHump(str));    }}
原创粉丝点击