I would like to match the data and replace with new value but if I put more than 5908 lines of data in HashMap. It's given error. How to solved this issue or another solution?
String str = "aaa bob ccc ddd .....";
HashMap<String, String> map = new HashMap<>();
map.put("aaa","eee"); // data that I would like to match and replace it
map.put("ddd","fff");
.
.
. // more than 5908 lines
.
.
map.put("zzz"."yyy");
Pattern pattern = Pattern.compile("([a-zA-Z_]+)");
Matcher matcher = pattern.matcher(str) // matching process
StringBuffer sb = new StringBuffer();
while(matcher.find()) { // if found and replace
String replace = map.get(matcher.group());
if (replace == null) { // if not just print it back
replace = matcher.group();
}
matcher.appendReplacement(sb, replace + "");
}
matcher.appendTail(sb);
System.out.println(sb);