java String转大写
时间: 2023-11-02 16:01:52 浏览: 33
在Java中,你可以使用String类的toUpperCase()方法将字符串转换为大写。该方法会返回一个新的字符串,其中所有的字母都被转换成大写。下面是一个示例代码:
```
String str = "hello";
String upperCaseStr = str.toUpperCase();
```
在上面的代码中,将字符串"hello"转换为大写,得到的结果是"HELLO"。
相关问题
java string 转大写
要将 Java 字符串转换为大写,可以使用 String 类的 toUpperCase() 方法。例如:
```java
String str = "Hello World";
String upper = str.toUpperCase();
System.out.println(upper); // 输出 "HELLO WORLD"
```
该方法返回一个新的字符串,其中所有字母都被转换为大写。原始字符串本身不会被修改。
java string转驼峰命名
要将一个Java字符串转换为驼峰命名,你可以使用以下方法:
```java
public static String toCamelCase(String str) {
StringBuilder result = new StringBuilder();
boolean nextUpperCase = false;
for (int i = 0; i < str.length(); i++) {
char currentChar = str.charAt(i);
if (currentChar == '_') {
nextUpperCase = true;
} else if (nextUpperCase) {
result.append(Character.toUpperCase(currentChar));
nextUpperCase = false;
} else {
result.append(Character.toLowerCase(currentChar));
}
}
return result.toString();
}
```
你可以调用这个方法并传入你想要转换的字符串作为参数。这个方法将把下划线后的每个字母转换为大写,并移除下划线。例如,"hello_world" 将会被转换为 "helloWorld"。