Here you can find the source of underscore(String camel)
Parameter | Description |
---|---|
camel | camel case input |
public static String underscore(String camel)
//package com.java2s; //License from project: LGPL import java.util.ArrayList; import java.util.List; public class Main { /**// w w w.ja v a 2s . c o m * Converts a CamelCase string to underscores: "AliceInWonderLand" becomes: * "alice_in_wonderland" * * @param camel camel case input * @return result converted to underscores. */ public static String underscore(String camel) { List<Integer> upper = new ArrayList<Integer>(); byte[] bytes = camel.getBytes(); for (int i = 0; i < bytes.length; i++) { byte b = bytes[i]; if (b < 97 || b > 122) { upper.add(i); } } StringBuffer b = new StringBuffer(camel); for (int i = upper.size() - 1; i >= 0; i--) { Integer index = upper.get(i); if (index != 0) b.insert(index, "_"); } return b.toString().toLowerCase(); } }