码迷,mamicode.com
首页 > 编程语言 > 详细

Java replace & replaceAll

时间:2015-11-04 12:56:21      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

Java字符串中需要对一些字符进行替换,用到最多的是replace和replaceAll两个方法。这两个方法在使用的时候需要注意:

replace:

public String replace (CharSequence target, CharSequence replacement)

Added in API level 1

Returns a copy of this string after replacing occurrences of target replaced with replacement. The string is processed from the beginning to the end.

Throws

NullPointerException
if target or replacement is null.

从上面的注释可以看出,该方法是将替换以后的字符拷贝返回的,原字符串并没有发生改变。

Java replace & replaceAll

标签:

原文地址:http://www.cnblogs.com/ithaibo-sit/p/4935530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!