Most efficient way to use replace multiple words in a string

java, replace

Solution

This functionality is already implemented in Commons Lang's `StringUtils` class.

StringUtils.replaceEach(String text, String[] searchList, String[] replacementList)

Problem

At the moment I'm doing Example: ``` line.replaceAll(",","").replaceAll("cat","dog").replaceAll("football","rugby"); ``` I think that it ugly. Not sure a better way to do this? Maybe loop through a hashmap? EDIT: By efficiency I mean better code style and flexibility

Original source

Related problems