将方法名称转换为字段名称
//package com.nowjava; /* *来 自 N o w J a v a . c o m */ import java.util.Locale; public class Main { public static void main(String[] argv) throws Exception { String methodName = "nowjava.com"; System.out.println(m2f(methodName)); } public static final int SET_START = "set".length(); public static final int SET_END = SET_START + 1; public static final int IS_START = "is".length(); /* n o w j a v a . c o m - 时 代 Java 提 供 */ public static final int IS_END = IS_START + 1; public static String m2f(String methodName) { if (methodName.startsWith("set") || methodName.startsWith("get")) { return methodName.substring(SET_START, SET_END).toLowerCase( Locale.CHINA) + methodName.substring(SET_END); } else if (methodName.startsWith("is")) { return methodName.substring(IS_START, IS_END).toLowerC