用java将taskName 转换为task_name
时间: 2024-05-01 22:23:12 浏览: 8
可以使用以下代码将 taskName 转换为 task_name:
```java
String taskName = "taskName";
String taskNameWithUnderscore = taskName.replaceAll("([A-Z]+)", "_$1").toLowerCase();
System.out.println(taskNameWithUnderscore); // 输出 task_name
```
这里的 `replaceAll()` 方法使用了正则表达式,将字符串中的大写字母前面添加下划线,并转换为小写字母。
相关推荐
![application/x-dosexec](https://img-home.csdnimg.cn/images/20210720083343.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)