Code example for CaseFormat

Methods: to

0
	 * 好玩的CaseFormat转换,在spaceSize->space_size之间转换,比如数据库表名与Java类名,变量名之间的转换。 
	 */ 
	@Test
	public void caseFormatByGuava() { 
		String name = "SPACE_SIZE";
		assertThat(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name)).isEqualTo("SpaceSize");
		assertThat(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name)).isEqualTo("spaceSize");
		assertThat(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_UNDERSCORE, name)).isEqualTo("space_size");
		assertThat(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name)).isEqualTo("space-size");
	} 
 
	@Test
	public void otherUtils() { 
		// 直接getBytes, 无需catch UnsupportedEncodingException, JDK7 有相应的StandardCharsets 
		byte[] bytes = "foobarbaz".getBytes(Charsets.UTF_8);
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE