Java 如何使用StringUtils获取大写字母?

Java 如何使用StringUtils获取大写字母?,java,string-utils,Java,String Utils,我似乎无法让StringUtils.capitalize实际大写我的整个单词字符串 我尝试过各种方法,但最终我得到的只是句子类型的案例。我尝试在我想要打印的内容中使用StringUtils.capitalize,但这也不起作用。我查的东西也帮不了我 File file = new File("C:\\Users\\mikek\\Desktop\\name.txt"); BufferedReader abc = new BufferedReader(new FileRe

我似乎无法让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();
 }
文件=
新文件(“C:\\Users\\mikek\\Desktop\\name.txt”);
BufferedReader abc=新BufferedReader(新文件读取器(文件));
列表数据=新的ArrayList();
字符串s;
字符串t;
而((s=abc.readLine()!=null){
数据。添加;
System.out.println(“公共静态最终块”+s.toUpperCase()+”=new”
+StringUtils.s.大写。替换(“\”,“)+”(\“+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();
 }
文件=
新文件(“C:\\Users\\mikek\\Desktop\\name.txt”);
BufferedReader abc=新BufferedReader(新文件读取器(文件));
列表数据=新的ArrayList();
字符串s;
而((s=abc.readLine())!=null){
数据。添加;
字符串“”;
String[]words=s.split(“”);
for(字符串w:单词){
camelcaseStation+=w.substring(0,1).toUpperCase()+w.substring(1)+”;
}
camelcaseStation=camelcaseStation.substring(0,camelcaseStation.length()-1);
System.out.println(“公共静态最终块”+s.toUpperCase()+”=new”
+替换(“,”)+“(\“+s+”,Material.ROCK);”;
}
abc.close();
}
现在我得到了(对于System.out.println的整个部分):
“public static final Block carbon_Block=new CharcoalBlock(“carbon_Block”,Material.ROCK);”就像我想要的那样。

我不明白。你除了
carbon Block
之外,还想把它存储在
数据中吗?文档上说“将字符串大写,将第一个字符按字符大小写更改为标题大小写。toTitleCase(int)。没有其他字符被更改。“,因此它不必担心字符串中的其他单词。它只使用第一个字符,其他字符都不用。文档还建议查看
WordUtils.capitalize(字符串)
。你应该接受他们的建议。@Luiggi我正在尝试制作一个mod工具。添加每个项目非常繁琐,我写这篇文章是为了提高效率。实际上,我正在生成代码以复制/粘贴到我的mod中。调用
data.add(t)后更改
t
不会更改
数据中的内容
。它只是使变量
t
指向一个不同的字符串对象,一个从未添加到任何列表中的对象。VGR因此,基本上,当我从文本文件中引入“carcor\u block”时,“carcor\u block”变成字符串,并用编辑那一个字符串?就像,它变成了“木炭块”,因为.capitalize只大写每个字符串,我没有做任何事情使它变成两个字符串?(如果这有意义的话)当我将s.split(“”)替换为s.split(“”)时,这起到了作用。然后我添加了camelcaseStation.replace(“,”),而不是t。谢谢!