提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取Getter方法名称
/* nowjava.com */ //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { String property = "nowjava.com"; System.out.println(getGetterMethodName(property)); } public static String getGetterMethodName(String property) { StringBuilder sb = new StringBuilder(); sb.append(property); if (Character.isLowerCase(sb.charAt(0))) { if (sb.length() == 1 || !Character.isUpperCase(sb.charAt(1))) { sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); } }