我对CamelCase有疑问.你有这个缩写:Unesco = United Nations Educational, Scientific and Cultural Organization.
你应该写: unitedNationsEducationalScientificAndCulturalOrganization
但是如果你需要写首字母缩略词怎么办?就像是:
getUnescoProperties();
Run Code Online (Sandbox Code Playgroud)
用这种方式写它是对的吗? getUnescoProperties() OR getUNESCOProperties();
给定字符串"ThisStringHasNoSpacesButItDoesHaveCapitals",在大写字母之前添加空格的最佳方法是什么.所以结束字符串将是"这个字符串没有空格,但它有资本"
以下是我使用RegEx的尝试
System.Text.RegularExpressions.Regex.Replace(value, "[A-Z]", " $0")
Run Code Online (Sandbox Code Playgroud) 通过java反射如何检查方法名是否在camelCase中?例如
import java.lang.reflect.*;
public class TestClass {
private int simpleMethod(
Object p, int x) throws NullPointerException
{
if (p == null)
throw new NullPointerException();
return x;
}
public static void main(String args[])
{
try {
Class cls = Class.forName("method1");
Method methlist[]
= cls.getDeclaredMethods();
for (int i = 0; i < methlist.length;
i++) {
Method m = methlist[i];
System.out.println("name= " + m.getName());
}
}
catch (Throwable e) {
System.err.println(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里我得到方法名称simpleMethod和main我必须检查这些名称是否在camelCase中.