java中字符串的替换

来源:互联网 发布:android sdk源码下载 编辑:程序博客网 时间:2024/05/17 08:00

例如有字符串:

temp1="516433413226212166644535535214" 

1.如果要替换掉所有的字符“5”,使用

temp1=temp1.replace("5","0");

temp1=016433413226212166644030030214

2.如果要替换掉第一个的字符“5”,使用

 temp1=temp1.replaceFirst("5","0");

temp1=016433413226212166644535535214

0 0