1.各种格式举例
转自官网中的格式与举例。
Format | Example |
LOWER_CAMEL | lowerCamel |
LOWER_HYPHEN | lower-hyphen |
LOWER_UNDERSCORE | lower_underscore |
UPPER_CAMEL | UpperCamel |
UPPER_UNDERSCORE | UPPER_UNDERSCORE |
常用方法public final String to(CaseFormat format,String str)。将str转换成format格式。
package string;
import com.google.common.base.CaseFormat;
public class CaseFormatInstance {
public static void test() {
/**
* Format Example
* LOWER_CAMEL lowerCamel
* LOWER_HYPHEN lower-hyphen
* LOWER_UNDERSCORE lower_underscore
* UPPER_CAMEL UpperCamel
* UPPER_UNDERSCORE UPPER_UNDERSCORE
**/
//将UPPER_UNDERSCORE格式的字符串转变为LOWER_CAMEL格式。
System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,
"YUAN_RQ,hi,CSDN_China"));
//输出结果:yuanRq,hi,csdnChina
}
public static void main(String[] args) {
test();
}
}