如何使用 StringUtils 获取 UpperCamelCase?

How to get UpperCamelCase using StringUtils?

我似乎无法 StringUtils.capitalize 实际将我的整个单词字符串大写。

我尝试了各种方法,但我最终还是得到了句子类型的大小写。我尝试在要打印的内容中使用 StringUtils.capitalize,但这也不起作用。我查找的内容也对我没有帮助。

  File file = 
      new File("C:\Users\mikek\Desktop\name.txt"); 
    BufferedReader abc = new BufferedReader(new FileReader(file));
List<String> data = new ArrayList<String>();
String s;
String t;
while((s=abc.readLine()!=null) {
    data.add(s);

    System.out.println("public static final Block " + s.toUpperCase() + "     = new "
+  StringUtils.capitalize(s).replace("_","") + "(\"" + s + "\", Material.ROCK);");
}

abc.close();
 }

预期:木炭块 得到:木炭块

这个怎么样??

        String s = "camel case word";
        String camelCaseSentence = "";
        String[] words = s.split(" ");
        for(String w:words){
            camelCaseSentence += w.substring(0,1).toUpperCase() + w.substring(1) + " ";

        }
        camelCaseSentence = camelCaseSentence.substring(0, camelCaseSentence.length()-1);
        System.out.println(camelCaseSentence);

Chris Katric 帮助我发现的内容:

File file = 
  new File("C:\Users\mikek\Desktop\name.txt"); 
BufferedReader abc = new BufferedReader(new FileReader(file));
List<String> data = new ArrayList<String>();
String s;

while((s=abc.readLine())!=null) {
data.add(s);
String camelCaseSentence = "";
    String[] words = s.split("_");
    for(String w:words){
        camelCaseSentence += w.substring(0,1).toUpperCase() + w.substring(1) + " ";

    }
    camelCaseSentence = camelCaseSentence.substring(0, camelCaseSentence.length()-1);

System.out.println("public static final Block " + s.toUpperCase() + " = new "
+  camelCaseSentence.replace(" ", "") + "(\"" + s + "\", Material.ROCK);");
}

abc.close();
 }

现在我得到(对于 System.out.println 的完整部分): "public static final Block CHARCOAL_BLOCK = new CharcoalBlock("charcoal_block", Material.ROCK);"就像我想要的那样。