/*
* 思路:
* 1.首先将字符串使用分割方法按照空格进行分割,存入字符串数组
* 2.定义一个新数组,其长度等于分割后存入字符串数组的长度
* 3.遍历字符串数组,将字符串数组第一个元素取出,剪切第一个字符使其变为大写,
* 再加上其剩余字符,连接起来存入到新数组
*
* */
String str = "let there be light";
String[] strNew = str.split(" ");
String[] strTemp = new String[strNew.length];
int i = 0;
while(i<strNew.length) {
System.out.println(strTemp[i] = strNew[i].substring(0,1).toUpperCase() + strNew[i].substring(1));
i++;
}
借鉴了https://blog.youkuaiyun.com/huaijiu123/article/details/83448587
本文介绍了一种使用Java实现字符串中每个单词首字母大写的算法。通过将字符串按空格分割,然后对每个单词的首字母进行大写转换,并重新组合成新的字符串。此方法适用于希望规范化显示文本的应用场景。
1648

被折叠的 条评论
为什么被折叠?



