Case Format
Google Guava is a java library with lot of utilities and reusable components.
This requires the library guava-10.0.jar to be in classpath.
The following example shows using various CaseFormat conversions.
package com.bethecoder.tutorials.guava.base_tests;
import com.google.common.base.CaseFormat;
public class CaseFormatTest {
/**
* @param args
*/
public static void main ( String [] args ) {
String str = CaseFormat.LOWER_CAMEL.to ( CaseFormat.UPPER_UNDERSCORE, "studentName" ) ;
System.out.println ( str ) ; //STUDENT_NAME
str = CaseFormat.UPPER_UNDERSCORE.to ( CaseFormat.LOWER_CAMEL, "STUDENT_NAME" ) ;
System.out.println ( str ) ; //studentName
str = CaseFormat.LOWER_HYPHEN.to ( CaseFormat.UPPER_CAMEL, "student-name" ) ;
System.out.println ( str ) ; //StudentName
str = CaseFormat.UPPER_CAMEL.to ( CaseFormat.LOWER_HYPHEN, "StudentName" ) ;
System.out.println ( str ) ; //student-name
}
}
It gives the following output,
STUDENT_NAME
studentName
StudentName
student-name