Replace all occurrences of substring in a string - which is more efficient in Java?

前端 未结 5 581
轮回少年
轮回少年 2020-12-15 09:53

I know of two ways of replacing all occurrences of substring in a string.

The regex way (assuming \"substring-to-be-replaced\" doesn\'t include regex specia

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 10:40

    Instead of using strings, which are immutable, use char arrays or some other mutable type (such as StringBuffer or StringBuilder).

提交回复
热议问题